├── .gitignore
├── .travis.yml
├── CHANGELOG.md
├── COPYING
├── Cask
├── Makefile
├── README.md
├── README.tmp-imenu-notes
├── nqp-mode.el
├── raku-detect.el
├── raku-font-lock.el
├── raku-imenu.el
├── raku-indent.el
├── raku-mode.el
├── raku-repl.el
├── raku-skeletons.el
├── raku-unicode-menu.el
└── test
├── raku-mode-test.el
├── test-helper.el
├── test-imenu.nqp
├── test-imenu.p6
└── test-smie.p6
/.gitignore:
--------------------------------------------------------------------------------
1 | *.elc
2 | /.cask/
3 | dist/
4 | perl6-mode-pkg.el
5 | *~
6 | ert-profile
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: emacs-lisp
2 | env:
3 | - EMACS=emacs-snapshot
4 | before_install:
5 | # Nightly Emacs snapshot builds
6 | - sudo add-apt-repository -y ppa:ubuntu-elisp/ppa
7 | # Update and install the Emacs for our environment
8 | - sudo apt-get update -qq
9 | - sudo apt-get install -qq -yy ${EMACS}-nox
10 | # Install and bootstrap cask
11 | - curl -fsSL https://raw.githubusercontent.com/cask/cask/master/go | python
12 | - export PATH="${HOME}/.cask/bin:$PATH"
13 | install:
14 | - cask --debug --verbose install
15 | script:
16 | - make compile test
17 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to this project will be documented in this file.
4 |
5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6 |
7 | ## [0.2.1] - 2021-09-13
8 | ### Removed
9 | - 'pkg-info' dependency (PR 53)
10 |
11 |
12 | ## [0.2.0] - 2021-04-12
13 | ### Added
14 | - `QUIT`, `DOC`, `CLOSE` phasers to font-lock
15 | - `ge` operator font-lock
16 |
17 | ### Changed
18 |
19 | - Change default repl keybindings.
20 | - Fix hanging assignment indentation.
21 |
22 | ### Removed
23 |
24 | - `START` phaser.
25 |
26 | ## [0.1.0]
27 | ### Added
28 | - Basic syntax highlighting
29 |
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/Cask:
--------------------------------------------------------------------------------
1 | (source gnu)
2 | (source melpa)
3 |
4 | (package-file "raku-mode.el")
5 |
6 | (files "*.el")
7 |
8 | (development
9 | (depends-on "ert-runner"))
10 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | CASK = cask
2 | EMACS = emacs
3 | EMACSFLAGS = --eval "(add-to-list 'load-path \".\")"
4 | TESTFLAGS =
5 |
6 | export EMACS
7 |
8 | PKGDIR := $(shell EMACS=$(EMACS) $(CASK) package-directory)
9 |
10 | SRCS := $(wildcard *.el)
11 | OBJS = $(SRCS:.el=.elc)
12 |
13 | .PHONY: compile test clean
14 |
15 | compile: $(OBJS)
16 |
17 | clean:
18 | rm -rf $(OBJS) dist raku-mode-pkg.el
19 |
20 | test: $(PKGDIR)
21 | $(CASK) exec ert-runner $(TESTFLAGS)
22 |
23 | %.elc : %.el $(PKGDIR)
24 | $(CASK) exec $(EMACS) -Q --batch $(EMACSFLAGS) -f batch-byte-compile $<
25 |
26 | $(PKGDIR) : Cask
27 | $(CASK) install
28 | touch $(PKGDIR)
29 |
30 | dist:
31 | $(CASK) package
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Raku Mode
2 |
3 | [![License GPL 3][badge-license]][copying]
4 | [](http://melpa.org/#/perl6-mode)
5 | [![travis][badge-travis]][travis]
6 |
7 | Raku mode lets you edit Raku code with [GNU Emacs][] 24.
8 |
9 | This mode needs GNU Emacs 24.4.
10 |
11 | ## Features
12 |
13 | * Basic syntax highlighting
14 | * Basic indentation
15 | * Identifier index menu (variables, subs, classes, etc.)
16 | * REPL interaction
17 |
18 | #### Planned
19 |
20 | * Complete syntax highlighting
21 | * Better indentation support (uses Emacs SMIE grammar, see the Emacs manual)
22 | * Autocompletion
23 | * Possible integration with Raku language server
24 | * Help system
25 | * ETags support
26 | * `find-file-at-point` for module names
27 | * Electricity (`electric-pair-mode` needs some context-sensitive help)
28 | * Unicode character map
29 | * Better HEREDOC support (currently not very stable)
30 |
31 | #### Not planned
32 |
33 | * Syntax checking (use [flycheck-raku][])
34 |
35 | ## Installation
36 |
37 | With [`use-package`][use-package] in your init file:
38 |
39 | ```el
40 | (use-package raku-mode
41 | :ensure t
42 | :defer t)
43 | ```
44 |
45 | Or in your [`Cask`][cask] file:
46 |
47 | ```el
48 | (source melpa)
49 |
50 | (depends-on "raku-mode")
51 | ```
52 | Or manually from [MELPA][] with M-x package-refresh-contents
53 | and M-x package-install RET raku-mode.
54 |
55 | ## Usage
56 |
57 | Just visit Raku files.
58 |
59 | The major mode will be autoloaded whenever a Raku file is visited.
60 | This includes any file with `raku` in the shebang, as well as any file
61 | with a `.p6`, `.pm6`, or `.pl6` extension. It also applies to any `.pm`,
62 | `.pl`, and `.t` files whose first line of code looks like Raku.
63 |
64 | Start the REPL with M-x run-raku RET. The following
65 | keybindings are available to interact with the REPL:
66 |
67 | * C-c C-l: Send the current **l**ine to the REPL
68 | * C-c C-r: Send the selected **r**egion to the REPL
69 | * C-c C-b: Send the whole **b**uffer to the REPL
70 |
71 | The REPL will start if needed with this keybindings.
72 |
73 | Use M-x customize-group RET raku to customize Raku Mode.
74 |
75 | ## Template skeletons
76 |
77 | Included are two skeletons (file templates) that can be auto-inserted with
78 | auto-insert-mode:
79 |
80 | * `raku-script-skeleton`, and
81 | * `raku-module-skeleton`.
82 |
83 | To use them, add them to your auto-insert-alist (`M-x customize-option RET
84 | auto-insert-alist`) with the conditions of your choice.
85 |
86 | To insert them when you create a new file with the `.raku` or `.rakumod`
87 | extension, use the following matching regular expressions:
88 |
89 | * For `raku-script-skeleton`: `\.raku\'`.
90 | * For `raku-module-skeleton`: `\.rakumod\`.
91 |
92 | Alternatively you can add them in your .emacs using `define-auto-insert`:
93 |
94 | ```Emacs Lisp
95 | (define-auto-insert
96 | '("\\.rakumod\\'" . "Raku module skeleton")
97 | 'raku-module-skeleton)
98 | (define-auto-insert
99 | '("\\.raku\\'" . "Raku script skeleton")
100 | 'raku-script-skeleton)
101 | ```
102 |
103 | The full path to the Raku executable for the shebang, as well as the default
104 | auth information for a module can be defined in the Raku Skeleton customization
105 | group, `M-x customize-group RET raku-skeleton`.
106 |
107 | ## Contribute
108 |
109 | Pull requests are welcome.
110 |
111 | You might want to install [`cask`][cask] so you can run the test suite
112 | (with `make test`).
113 |
114 | ## Original Code
115 |
116 | The original version of this code can be found at
117 | [https://github.com/hinrik/perl6-mode](https://github.com/hinrik/perl6-mode)
118 |
119 | ## License
120 |
121 | Raku Mode is free software: you can redistribute it and/or modify it
122 | under the terms of the GNU General Public License as published by the
123 | Free Software Foundation, either version 3 of the License, or (at your
124 | option) any later version.
125 |
126 | Raku Mode is distributed in the hope that it will be useful, but
127 | WITHOUT ANY WARRANTY; without even the implied warranty of
128 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
129 | Public License for more details.
130 |
131 | See [`COPYING`][copying] for the complete license.
132 |
133 | [badge-license]: https://img.shields.io/badge/license-GPL_3-green.svg
134 | [COPYING]: https://github.com/hinrik/perl6-mode/blob/master/COPYING
135 | [travis]: https://travis-ci.org/hinrik/perl6-mode
136 | [badge-travis]: https://travis-ci.org/hinrik/perl6-mode.svg?branch=master
137 | [GNU Emacs]: https://www.gnu.org/software/emacs/
138 | [flycheck-raku]: https://github.com/Raku/flycheck-raku
139 | [MELPA]: http://melpa.milkbox.net/
140 | [use-package]: https://github.com/jwiegley/use-package
141 | [Cask]: http://cask.github.io/
142 | [Issue tracker]: https://github.com/hinrik/perl6-mode/issues
143 |
--------------------------------------------------------------------------------
/README.tmp-imenu-notes:
--------------------------------------------------------------------------------
1 | major modes:
2 |
3 | The mode should specify how Imenu should find the definitions or
4 | sections of a buffer, by setting up a buffer-local value for the
5 | variable imenu-generic-expression, for the two variables
6 | imenu-prev-index-position-function and
7 | imenu-extract-index-name-function, or for the variable
8 | imenu-create-index-function (see Imenu).
9 |
10 | Macro: defvar-local variable value &optional docstring
11 |
12 | This macro defines variable as a variable with initial value value
13 | and docstring, and marks it as automatically buffer-local. It is
14 | equivalent to calling defvar followed by
15 | make-variable-buffer-local. variable should be an unquoted symbol.
16 |
17 | 22.5 Imenu
18 |
19 | Imenu is a feature that lets users select a definition or section in
20 | the buffer, from a menu which lists all of them, to go directly to
21 | that location in the buffer. Imenu works by constructing a buffer
22 | index which lists the names and buffer positions of the definitions,
23 | or other named portions of the buffer; then the user can choose one of
24 | them and move point to it. Major modes can add a menu bar item to use
25 | Imenu using imenu-add-to-menubar.
26 |
27 | Command: imenu-add-to-menubar name
28 |
29 | This function defines a local menu bar item named name to run Imenu.
30 |
31 | The usual and simplest way is to set the variable imenu-generic-expression:
32 |
33 | Variable: imenu-generic-expression
34 |
35 | This variable, if non-nil, is a list that specifies regular
36 | expressions for finding definitions for Imenu. Simple elements of
37 | imenu-generic-expression look like this:
38 |
39 | (menu-title regexp index)
40 |
41 | Here, if menu-title is non-nil, it says that the matches for this
42 | element should go in a submenu of the buffer index; menu-title
43 | itself specifies the name for the submenu. If menu-title is nil, the
44 | matches for this element go directly in the top level of the buffer
45 | index.
46 |
47 | The second item in the list, regexp, is a regular expression (see
48 | Regular Expressions); anything in the buffer that it matches is
49 | considered a definition, something to mention in the buffer
50 | index.
51 |
52 | The third item, index, is a non-negative integer that indicates
53 | which subexpression in regexp matches the definition’s name.
54 |
--------------------------------------------------------------------------------
/nqp-mode.el:
--------------------------------------------------------------------------------
1 | ;;; raku-mode.el --- Major mode for editing Raku code -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2015 Hinrik Örn Sigurðsson
4 |
5 | ;; Author: Hinrik Örn Sigurðsson
6 | ;; URL: https://github.com/hinrik/perl6-mode
7 | ;; Keywords: languages
8 | ;; Version: 0.1-git
9 | ;; Package-Requires: ((emacs "24.4"))
10 |
11 | ;; This file is not part of GNU Emacs.
12 |
13 | ;; This program is free software: you can redistribute it and/or modify
14 | ;; it under the terms of the GNU General Public License as published by
15 | ;; the Free Software Foundation, either version 3 of the License, or
16 | ;; (at your option) any later version.
17 |
18 | ;; This program is distributed in the hope that it will be useful,
19 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 | ;; GNU General Public License for more details.
22 |
23 | ;; You should have received a copy of the GNU General Public License
24 | ;; along with this program. If not, see .
25 |
26 | ;;; Commentary:
27 |
28 | ;; GNU Emacs 24 major mode for editing Raku code.
29 |
30 | ;; Currently only provides very basic syntax highlighting.
31 |
32 | ;;; Code:
33 |
34 | (defgroup raku nil
35 | "Major mode for editing Raku code."
36 | :prefix "raku-"
37 | :group 'language)
38 |
39 | (require 'raku-detect)
40 | (require 'raku-font-lock)
41 | (require 'raku-indent)
42 | (require 'raku-imenu)
43 |
44 | ;;;###autoload
45 | (define-derived-mode raku-mode prog-mode "Raku"
46 | "Major mode for editing Raku code."
47 | ;; Syntaxification and font locking
48 | (setq-local syntax-propertize-function #'raku-syntax-propertize)
49 | (add-hook 'syntax-propertize-extend-region-functions #'syntax-propertize-multiline nil 'local)
50 | (setq-local font-lock-syntactic-face-function #'raku-font-lock-syntactic-face)
51 | (setq-local font-lock-defaults '(raku-font-lock-keywords nil nil))
52 | ;; Add imenu support for raku-mode. Note that imenu-generic-expression
53 | ;; is buffer-local, so we don't need a local-variable for it.
54 | (add-hook 'raku-mode-hook 'imenu-add-menubar-index)
55 | (setq imenu-generic-expression raku-imenu-generic-expression
56 | imenu-case-fold-search nil)
57 | ;; Comments
58 | (setq-local comment-start "#")
59 | (setq-local comment-start-skip "#+ *")
60 | (setq-local comment-use-syntax t)
61 | (setq-local comment-end "")
62 | ;; Indentation
63 | (smie-setup raku-smie-grammar #'raku-smie-rules
64 | :forward-token #'raku-smie--forward-token
65 | :backward-token #'raku-smie--backward-token))
66 |
67 | (provide 'raku-mode)
68 |
69 | ;; Local Variables:
70 | ;; coding: utf-8
71 | ;; indent-tabs-mode: nil
72 | ;; End:
73 |
74 | ;;; raku-mode.el ends here
75 |
--------------------------------------------------------------------------------
/raku-detect.el:
--------------------------------------------------------------------------------
1 | ;;; raku-detect.el --- Raku detection -*- lexical-binding: t; -*-
2 |
3 | ;;; Commentary:
4 |
5 | ;; Yes, we are adding to `magic-mode-alist' here. Raku uses the same
6 | ;; file extensions as Perl 5, and we want the mode to work out of the box.
7 | ;; So for those files we look at the first line of code to determine
8 | ;; whether to call `raku-mode' instead of `perl-mode'.
9 |
10 | ;;; Code:
11 |
12 | ;;;###autoload
13 | (add-to-list 'interpreter-mode-alist '("perl6\\|raku" . raku-mode))
14 |
15 | ;;;###autoload
16 | (add-to-list 'auto-mode-alist '("\\.p[lm]?6\\'" . raku-mode))
17 | ;;;###autoload
18 | (add-to-list 'auto-mode-alist '("\\.nqp\\'" . raku-mode))
19 | ;;;###autoload
20 | (add-to-list 'auto-mode-alist '("\\.raku\\(?:mod\\|test\\)?\\'" . raku-mode))
21 |
22 | ;;;###autoload
23 | (defconst raku-magic-pattern
24 | (rx line-start
25 | (0+ space)
26 | (or (and "use" (1+ space) "v6")
27 | (and (opt (and (or "my" "our") (1+ space)))
28 | (or "module" "class" "role" "grammar" "enum" "slang" "subset")))))
29 |
30 | ;;;###autoload
31 | (defun raku-magic-matcher ()
32 | "Check if the current buffer is a Raku file.
33 |
34 | Only looks at a buffer if it has a file extension of .t, .pl, or .pm.
35 |
36 | Scans the buffer (to a maximum of 4096 chars) for the first non-comment,
37 | non-whitespace line. Returns t if that line looks like Raku code,
38 | nil otherwise."
39 | (let ((case-fold-search nil))
40 | (when (and (stringp buffer-file-name)
41 | (string-match "\\.\\(?:t\\|p[lm]\\)\\'" buffer-file-name))
42 | (let ((keep-going t)
43 | (found-raku nil)
44 | (max-pos (min 4096 (point-max))))
45 | (while (and (< (point) max-pos)
46 | keep-going)
47 | (if (looking-at "^ *\\(?:#.*\\)?$")
48 | (beginning-of-line 2)
49 | (setq keep-going nil
50 | found-raku (looking-at raku-magic-pattern))))
51 | found-raku))))
52 |
53 | ;;;###autoload
54 | (add-to-list 'magic-mode-alist '(raku-magic-matcher . raku-mode))
55 |
56 | (provide 'raku-detect)
57 |
58 | ;; Local Variables:
59 | ;; coding: utf-8
60 | ;; indent-tabs-mode: nil
61 | ;; End:
62 |
63 | ;;; raku-detect.el ends here
64 |
--------------------------------------------------------------------------------
/raku-font-lock.el:
--------------------------------------------------------------------------------
1 | ;;; raku-font-lock.el --- Font locking and syntax propertizing for Raku -*- lexical-binding: t; -*-
2 |
3 | ;;; Commentary:
4 |
5 | ;; All syntaxification and font locking takes place here.
6 |
7 | ;;; Code:
8 |
9 | (defface raku-identifier '((t :inherit default))
10 | "Face for identifiers in Raku."
11 | :group 'raku-faces)
12 |
13 | (defface raku-number '((t :inherit font-lock-constant-face))
14 | "Face for number literals in Raku."
15 | :group 'raku-faces)
16 |
17 | (defface raku-number-addition '((t :inherit font-lock-type-face))
18 | "Face for additional characters attached to numbers."
19 | :group 'raku-faces)
20 |
21 | (defface raku-string '((t :inherit font-lock-string-face))
22 | "Face for strings in Raku."
23 | :group 'raku-faces)
24 |
25 | (defface raku-comment '((t :inherit font-lock-comment-face))
26 | "Face for comments in Raku."
27 | :group 'raku-faces)
28 |
29 | (defface raku-operator '((t :inherit font-lock-builtin-face))
30 | "Face for operators in Raku."
31 | :group 'raku-faces)
32 |
33 | (defface raku-type '((t :inherit font-lock-type-face))
34 | "Face for types in Raku."
35 | :group 'raku-faces)
36 |
37 | (defface raku-phaser '((t :inherit font-lock-preprocessor-face))
38 | "Face for phasers in Raku."
39 | :group 'raku-faces)
40 |
41 | (defface raku-exception '((t :inherit font-lock-keyword-face))
42 | "Face for exception keywords in Raku."
43 | :group 'raku-faces)
44 |
45 | (defface raku-declare '((t :inherit font-lock-keyword-face))
46 | "Face for declaration keywords in Raku."
47 | :group 'raku-faces)
48 |
49 | (defface raku-include '((t :inherit font-lock-keyword-face))
50 | "Face for include keywords in Raku."
51 | :group 'raku-faces)
52 |
53 | (defface raku-conditional '((t :inherit font-lock-keyword-face))
54 | "Face for conditional keywords in Raku."
55 | :group 'raku-faces)
56 |
57 | (defface raku-scope '((t :inherit font-lock-keyword-face))
58 | "Face for scope keywords in Raku."
59 | :group 'raku-faces)
60 |
61 | (defface raku-loop '((t :inherit font-lock-keyword-face))
62 | "Face for loop keywords in Raku."
63 | :group 'raku-faces)
64 |
65 | (defface raku-flow-control '((t :inherit font-lock-keyword-face))
66 | "Face for flow control keywords in Raku."
67 | :group 'raku-faces)
68 |
69 | (defface raku-pragma '((t :inherit font-lock-keyword-face))
70 | "Face for pragmas in Raku."
71 | :group 'raku-faces)
72 |
73 | (defface raku-type-constraint '((t :inherit font-lock-preprocessor-face))
74 | "Face for type constraint keywords in Raku."
75 | :group 'raku-faces)
76 |
77 | (defface raku-type-property '((t :inherit font-lock-builtin-face))
78 | "Face for type constraint properties in Raku."
79 | :group 'raku-faces)
80 |
81 | (defface raku-sigil '((t :inherit font-lock-variable-name-face))
82 | "Face for variable sigils in Raku."
83 | :group 'raku-faces)
84 |
85 | (defface raku-twigil '((t :inherit font-lock-type-face))
86 | "Face for variable twigils in Raku."
87 | :group 'raku-faces)
88 |
89 | (defface raku-var-package '((t :inherit font-lock-constant-face))
90 | "Face for variable names in Raku."
91 | :group 'raku-faces)
92 |
93 | (defface raku-var-name '((t :inherit font-lock-variable-name-face))
94 | "Face for variable names in Raku."
95 | :group 'raku-faces)
96 |
97 | (defface raku-var-name-mu '((t :inherit font-lock-variable-name-face))
98 | "Face for mu variable names in Raku."
99 | :group 'raku-faces)
100 |
101 | (defface raku-var-name-positional '((t :inherit font-lock-variable-name-face))
102 | "Face for positional variable names in Raku."
103 | :group 'raku-faces)
104 |
105 | (defface raku-var-name-associative '((t :inherit font-lock-variable-name-face))
106 | "Face for associative variable names in Raku."
107 | :group 'raku-faces)
108 |
109 | (defface raku-var-name-callable '((t :inherit font-lock-variable-name-face))
110 | "Face for callable variable names in Raku."
111 | :group 'raku-faces)
112 |
113 | (defface raku-version '((t :inherit font-lock-constant-face))
114 | "Face for version literals in Raku."
115 | :group 'raku-faces)
116 |
117 | (defface raku-label '((t :inherit font-lock-constant-face))
118 | "Face for block labels in Raku."
119 | :group 'raku-faces)
120 |
121 | (eval-when-compile
122 | (require 'rx)
123 |
124 | (defun raku-rx-symbol (form)
125 | "Translate FORM into a regular expression."
126 | (let ((body (cdr form)))
127 | (rx-to-string `(and symbol-start ,@body symbol-end) 'no-group)))
128 |
129 | (let ((rx-identifier (rx-to-string
130 | `(and (regex "[_[:alpha:]]")
131 | (0+ (regex "[_[:alnum:]]"))
132 | (0+ (any "-'") (regex "[_[:alpha:]]") (0+ (regex "[_[:alnum:]]"))))))
133 | (rx-metaoperator (rx-to-string
134 | `(or (and (regex "[^[:digit:]@%$]")
135 | (0+ (regex "[^\[\{\('\"[:space:]]")))
136 | (and (any "@%$")
137 | (regex "[^.?^=_[:alpha:]]\[\{\('\"[:space:]]")
138 | (0+ (regex "[^\[\{\('\"[:space:]]")))))))
139 | (defconst raku-rx-constituents
140 | `((symbol raku-rx-symbol 0 nil)
141 | (identifier . ,rx-identifier)
142 | (variable
143 | . ,(rx-to-string
144 | `(and (group (1+ (char "@$%&")))
145 | (group (opt (char ".^*?=!~:")))
146 | (group (opt (or (and "::" (0+ (regex ,rx-identifier) "::"))
147 | (1+ (regex ,rx-identifier) "::"))))
148 | (group (or (or digit (char "/!¢"))
149 | (and (regex ,rx-identifier) symbol-end))))))
150 | (variable-mu
151 | . ,(rx-to-string
152 | `(and (group (1+ (char "$")))
153 | (group (opt (char ".^*?=!~:")))
154 | (group (opt (or (and "::" (0+ (regex ,rx-identifier) "::"))
155 | (1+ (regex ,rx-identifier) "::"))))
156 | (group (or (or digit (char "/!¢"))
157 | (and (regex ,rx-identifier) symbol-end))))))
158 | (variable-positional
159 | . ,(rx-to-string
160 | `(and (group (1+ (char "@")))
161 | (group (opt (char ".^*?=!~:")))
162 | (group (opt (or (and "::" (0+ (regex ,rx-identifier) "::"))
163 | (1+ (regex ,rx-identifier) "::"))))
164 | (group (or (or digit (char "/!¢"))
165 | (and (regex ,rx-identifier) symbol-end))))))
166 | (variable-associative
167 | . ,(rx-to-string
168 | `(and (group (1+ (char "%")))
169 | (group (opt (char ".^*?=!~:")))
170 | (group (opt (or (and "::" (0+ (regex ,rx-identifier) "::"))
171 | (1+ (regex ,rx-identifier) "::"))))
172 | (group (or (or digit (char "/!¢"))
173 | (and (regex ,rx-identifier) symbol-end))))))
174 | (variable-callable
175 | . ,(rx-to-string
176 | `(and (group (1+ (char "&")))
177 | (group (opt (char ".^*?=!~:")))
178 | (group (opt (or (and "::" (0+ (regex ,rx-identifier) "::"))
179 | (1+ (regex ,rx-identifier) "::"))))
180 | (group (or (or digit (char "/!¢"))
181 | (and (regex ,rx-identifier) symbol-end))))))
182 | (reduce-operator
183 | . ,(rx-to-string
184 | `(and (0+ (any "RSXZ\["))
185 | (opt (any "RSXZ&"))
186 | (1+ "\[")
187 | (opt "\(")
188 | (regex ,rx-metaoperator)
189 | (opt "\)")
190 | (1+ "\]"))))
191 | (hyper-operator
192 | . ,(rx-to-string
193 | `(or (and "«" (regex ,rx-metaoperator) (char "«»"))
194 | (and "»" (regex ,rx-metaoperator) (opt (char "«»")))
195 | (and "<<" (regex ,rx-metaoperator) (or "<<" ">>"))
196 | (and ">>" (regex ,rx-metaoperator) (opt (or "<<" ">>")))
197 | (and (regex "[^[:digit:]\[\{\('\",:[:space:]]")
198 | (0+ (regex "[^\[\{\('\",:[:space:]]"))
199 | (or "«" "<<")))))
200 | (pre-declare
201 | . ,(rx (or "multi" "proto" "only")))
202 | (declare
203 | . ,(rx (or "macro" "sub" "submethod" "method" "category"
204 | "module" "class" "role" "package" "enum" "grammar"
205 | "slang" "subset")))
206 | (rule . ,(rx (or "regex" "rule" "token")))
207 | (include . ,(rx (or "use" "require unit")))
208 | (conditional . ,(rx (or "if" "else" "elsif" "unless" "with"
209 | "orwith" "without")))
210 | (scope . ,(rx (or "let" "my" "our" "state" "temp" "has" "constant")))
211 | (loop . ,(rx (or "for" "loop" "repeat" "while" "until" "gather" "given")))
212 | (flow-control
213 | . ,(rx (or "take" "do" "when" "next" "last" "redo" "return" "contend"
214 | "maybe" "defer" "start" "default" "exit" "make" "continue"
215 | "break" "goto" "leave" "async" "lift")))
216 | (phaser
217 | . ,(rx (or "BEGIN" "CHECK" "INIT" "FIRST" "ENTER" "LEAVE" "KEEP"
218 | "UNDO" "NEXT" "LAST" "PRE" "POST" "END" "CATCH" "CONTROL"
219 | "TEMP" "QUIT" "DOC" "CLOSE")))
220 | (exception . ,(rx (or "die" "fail" "try" "warn")))
221 | (pragma . ,(rx (or "oo" "fatal")))
222 | (type-constraint
223 | . ,(rx (or "does" "as" "but" "trusts" "of" "returns" "handles" "where"
224 | "augment" "supersede")))
225 | (type-property
226 | . ,(rx (or "signature" "context" "also" "shape" "prec" "irs" "ofs" "ors"
227 | "export" "deep" "binary" "unary" "reparsed" "rw" "parsed"
228 | "cached" "readonly" "defequiv" "will" "ref" "copy" "inline"
229 | "tighter" "looser" "equiv" "assoc" "required")))
230 | (operator-word
231 | . ,(rx (or "div" "xx" "x" "mod" "also" "leg" "cmp" "before" "after" "eq"
232 | "ne" "le" "lt" "not" "gt" "ge" "eqv" "ff" "fff" "and" "andthen"
233 | "or" "xor" "orelse" "extra" "lcm" "gcd" "o")))
234 | (operator-char . ,(rx (any "-:+/*~?|=^!%&,<>».;\\∈∉∋∌∩∪≼≽⊂⊃⊄⊅⊆⊇⊈⊉⊍⊎⊖∅∘")))
235 | (set-operator
236 | . ,(rx (opt "R")
237 | "\("
238 | (or (char "-^.+|&")
239 | (and (char "<>") (opt (char "=+")))
240 | "cont"
241 | "elem")
242 | "\)"))
243 | (rsxz-operator
244 | . ,(rx
245 | symbol-start
246 | (any "RSXZ")
247 | (or (or (and (or "div" "mod" "gcd" "lcm" "xx" "x" "does" "but" "cmp"
248 | "leg" "eq" "ne" "gt" "ge" "lt" "le" "before" "after"
249 | "eqv" "min" "max" "not" "so" "andthen" "and" "or"
250 | "orelse")
251 | symbol-end)
252 | (any ".,")
253 | (1+ (regex "[^:\[.,[:space:][:alnum:]]")))
254 | symbol-end)))
255 | (low-type
256 | . ,(rx (or "int" "int1" "int2" "int4" "int8" "int16" "int32" "int64"
257 | "rat" "rat1" "rat2" "rat4" "rat8" "rat16" "rat32" "rat64"
258 | "buf" "buf1" "buf2" "buf4" "buf8" "buf16" "buf32" "buf64"
259 | "uint" "uint1" "uint2" "uint4" "uint8" "uint16" "uint32"
260 | "uint64" "utf8" "utf16" "utf32" "bit" "bool" "bag" "set"
261 | "mix" "num" "complex")))
262 | (high-type
263 | . ,(rx (or "Object" "Any" "Junction" "Whatever" "Capture" "Match"
264 | "Signature" "Proxy" "Matcher" "Package" "Module" "Class"
265 | "Grammar" "Scalar" "Array" "Hash" "KeyHash" "KeySet" "KeyBag"
266 | "Pair" "List" "Seq" "Range" "Set" "Bag" "BagHash" "Mapping" "Void"
267 | "Undef" "Failure" "Exception" "Code" "Block" "Routine" "Sub"
268 | "Macro" "Method" "Submethod" "Regex" "Str" "Blob" "Char" "Map"
269 | "Byte" "Parcel" "Codepoint" "Grapheme" "StrPos" "StrLen"
270 | "Version" "Num" "Complex" "Bit" "True" "False" "Order" "Same"
271 | "Less" "More" "Increasing" "Decreasing" "Ordered" "Callable"
272 | "AnyChar" "Positional" "Associative" "Ordering" "KeyExtractor"
273 | "Comparator" "OrderingPair" "IO" "KitchenSink" "Role" "Int" "Bool"
274 | "Rat" "Buf" "UInt" "Abstraction" "Numeric" "Real" "Nil" "Mu")))
275 | (version . ,(rx "v" (1+ digit) (0+ "." (or "*" (1+ digit))) (opt "+")))
276 | (number
277 | . ,(rx
278 | (group-n 1
279 | (or (and (1+ digit)
280 | (0+ (and "_" (1+ digit)))
281 | (opt "."
282 | (1+ digit)
283 | (0+ (and "_" (1+ digit)))))
284 | (and "."
285 | (1+ digit)
286 | (0+ (and "_" (1+ digit))))))
287 | (opt (group-n 2 (any "Ee"))
288 | (group-n 3 (opt "-") (1+ digit) (0+ "_" (1+ digit))))
289 | (opt (group-n 4 "i"))))
290 | (base-number
291 | . ,(rx symbol-start
292 | (group-n 1 "0")
293 | (or (and
294 | (group-n 2 "o")
295 | (group-n 3 (any "0-7") (0+ (any "0-7_"))))
296 | (and
297 | (group-n 2 "b")
298 | (group-n 3 (any "0-1") (0+ (any "0-1_"))))
299 | (and
300 | (group-n 2 "x")
301 | (group-n 3 (regex "[[:xdigit:]]") (0+ (regex "[[:xdigit:]_]"))))
302 | (and
303 | (group-n 2 "d")
304 | (group-n 3 (regex "[[:digit:]]") (0+ (regex "[[:digit:]_]"))))))))))
305 |
306 | (defmacro raku-rx (&rest sexps)
307 | "Specialized `rx' variant for raku-mode."
308 | (let ((rx-constituents (append raku-rx-constituents rx-constituents)))
309 | (cond ((null sexps)
310 | (error "No regexp"))
311 | ((cdr sexps)
312 | (rx-to-string `(and ,@sexps) t))
313 | (t
314 | (rx-to-string (car sexps) t))))))
315 |
316 | (defconst raku-mode-syntax-table
317 | (let ((table (make-syntax-table)))
318 | ;; single-quoted strings
319 | (modify-syntax-entry ?' "\"" table)
320 | ;; these are all punctuation chars, not word or symbol chars
321 | (modify-syntax-entry ?$ "." table)
322 | (modify-syntax-entry ?% "." table)
323 | (modify-syntax-entry ?& "." table)
324 | (modify-syntax-entry ?* "." table)
325 | (modify-syntax-entry ?+ "." table)
326 | (modify-syntax-entry ?- "." table)
327 | (modify-syntax-entry ?/ "." table)
328 | (modify-syntax-entry ?< "." table)
329 | (modify-syntax-entry ?= "." table)
330 | (modify-syntax-entry ?> "." table)
331 | (modify-syntax-entry ?| "." table)
332 | table)
333 | "The top level syntax table for Raku.")
334 |
335 | (defconst raku-bracket-syntax-table
336 | (let ((table (make-syntax-table raku-mode-syntax-table)))
337 | (modify-syntax-entry ?< "(>" table)
338 | (modify-syntax-entry ?> ")<" table)
339 | (modify-syntax-entry ?« "(»" table)
340 | (modify-syntax-entry ?» ")«" table)
341 | (modify-syntax-entry ?‘ "(’" table)
342 | (modify-syntax-entry ?’ ")‘" table)
343 | (modify-syntax-entry ?“ "(”" table)
344 | (modify-syntax-entry ?” ")“" table)
345 | table)
346 | "Syntax table for bracketing constructs.")
347 |
348 | (defun raku-syntax-context (&optional state)
349 | "Return the syntactic context at the parse state of STATE.
350 |
351 | If STATE is not provided, the return value of `syntax-ppss' will be used."
352 | (let* ((state (or state (syntax-ppss)))
353 | (in-string (nth 3 state))
354 | (in-comment (nth 4 state)))
355 | (cond
356 | (in-string 'string)
357 | (in-comment 'comment)
358 | (t nil))))
359 |
360 | (defun raku-forward-brackets (open close length)
361 | "Move point past the end of a bracketed structure.
362 |
363 | Skips over any nested balanced brackets.
364 |
365 | OPEN and CLOSE are the bracketing characters (e.g. ?< and ?>).
366 | LENGTH is the length of the brackets (e.g. 2 for a <>)."
367 | (let ((pattern (rx-to-string `(and (group (0+ "\\"))
368 | (or (group (= ,length ,open))
369 | (group (= ,length ,close))))))
370 | (found-closing nil)
371 | (depth 1))
372 | (while (and (not found-closing)
373 | (< (point) (point-max)))
374 | (re-search-forward pattern (point-max) 'noerror)
375 | (when (or (not (match-string 1))
376 | (= 0 (% (length (match-string 1)) 2)))
377 | (cond ((match-string 2)
378 | (if (looking-at (rx-to-string open))
379 | (re-search-forward (rx-to-string `(1+ ,open)))
380 | (setq depth (1+ depth))))
381 | ((match-string 3)
382 | (setq depth (1- depth))
383 | (when (eq depth 0)
384 | (setq found-closing t))))))))
385 |
386 | (defun raku-syntax-propertize-delimiters (syntax &optional offset)
387 | "Add syntax properties to a delimited region.
388 |
389 | SYNTAX is the type of syntax to apply to the delimiters \(such as \"!\"\).
390 |
391 | OFFSET can be used to shift the starting position (relative to point) of the
392 | opening delimiter."
393 | (with-syntax-table raku-bracket-syntax-table
394 | (when (and (following-char)
395 | (eq ?\( (char-syntax (following-char))))
396 | (let* ((delim-beg (+ (point) (or offset 0)))
397 | (open-delim (following-char))
398 | (close-delim (matching-paren open-delim)))
399 | (put-text-property delim-beg (1+ delim-beg)
400 | 'syntax-table (string-to-syntax syntax))
401 | (re-search-forward (rx-to-string `(1+ ,open-delim)))
402 | (let ((delim-length (length (match-string 0))))
403 | (raku-forward-brackets open-delim close-delim delim-length)
404 | (let ((delim-end (point)))
405 | (put-text-property delim-beg delim-end 'syntax-multiline t)
406 | (put-text-property (- delim-end 1) delim-end
407 | 'syntax-table (string-to-syntax syntax)))))
408 | t)))
409 |
410 | (defun raku-syntax-propertize-comment (limit)
411 | "Add syntax properties to comments."
412 | (unless (save-excursion
413 | (and (re-search-forward "\\=[`|=]" (1+ (point)) t)
414 | ;; embedded/multiline comment
415 | (raku-syntax-propertize-delimiters "!" -2)))
416 | ;; single-line comment
417 | (put-text-property (1- (point)) (point)
418 | 'syntax-table (string-to-syntax "<"))
419 | (if (re-search-forward "\n" limit 'noerror)
420 | (put-text-property (1- (point)) (point)
421 | 'syntax-table (string-to-syntax ">")))))
422 |
423 | (defun raku-syntax-propertize-pod-code-blocks (limit)
424 | "Add syntax properties to code blocks in POD."
425 | (while (search-forward "=begin code" limit t)
426 | (let ((code-beg (point))
427 | (code-end (- (search-forward "=end code" limit t)
428 | (length "=end code"))))
429 | (put-text-property code-beg (1+ code-beg)
430 | 'syntax-table (string-to-syntax ">"))
431 | (put-text-property (1- code-end) code-end
432 | 'syntax-table (string-to-syntax "<"))
433 | (remove-text-properties code-beg code-end '(syntax-multiline nil))
434 | (raku-syntax-propertize code-beg code-end))))
435 |
436 | (defun raku-syntax-propertize-pod-inline-code (limit)
437 | "Add syntax properties to inline code blocks in POD."
438 | (while (and
439 | (re-search-forward "^\s*\n\s+[^\s]" limit t))
440 | (backward-char)
441 | (unless (looking-at "=\(begin\|end\|head\|for\|para\|item\|defn\|comment\)")
442 | (let ((code-beg (1- (point))))
443 | (re-search-forward "^[^\s]" limit t)
444 | (when (looking-back "^[^\s]" code-beg)
445 | (forward-line -1)
446 | (end-of-line))
447 | (put-text-property (1- code-beg) code-beg
448 | 'syntax-table (string-to-syntax ">"))
449 | (put-text-property (point) (1+ (point))
450 | 'syntax-table (string-to-syntax "<"))
451 | (remove-text-properties code-beg (point) '(syntax-multiline nil))
452 | (raku-syntax-propertize code-beg (point))))))
453 |
454 | (defun raku-syntax-propertize-pod (limit)
455 | "Add syntax properties to POD."
456 | (let ((pod-beg (- (point) (length "=begin pod")))
457 | (pod-end (search-forward "=end pod" limit t)))
458 | (save-excursion
459 | (put-text-property (1- pod-beg) pod-beg
460 | 'syntax-table (string-to-syntax "<"))
461 | (put-text-property pod-end (1+ pod-end)
462 | 'syntax-table (string-to-syntax ">"))
463 | (put-text-property pod-beg pod-end
464 | 'syntax-multiline t)
465 | (goto-char pod-beg)
466 | (raku-syntax-propertize-pod-code-blocks pod-end)
467 | (goto-char pod-beg)
468 | (raku-syntax-propertize-pod-inline-code pod-end))))
469 |
470 | (defun raku-syntax-propertize-angles (open-angles)
471 | "Add syntax properties to angle-bracketed quotes (e.g. and «bar»).
472 |
473 | OPEN-ANGLES is the opening delimiter (e.g. \"«\" or \"<<\")."
474 | (with-syntax-table raku-bracket-syntax-table
475 | (let* ((angle-length (length open-angles))
476 | (open-angle (string-to-char open-angles))
477 | (close-angle (matching-paren open-angle))
478 | (quote-beg (- (point) angle-length))
479 | (line-beg (point-at-bol)))
480 | (when
481 | (and (not (or (looking-at (rx-to-string `(or "=" (= 2 (char "-=")))))
482 | (looking-at (rx-to-string `(and (** 1 2 "-") ,close-angle)))
483 | (looking-back (rx-to-string `(and (char "+~=!") ,open-angle)) 2)))
484 | (or (not (looking-at "[\s\n]"))
485 | (not (looking-back (rx-to-string `(and (char "\s\n") ,open-angle)) 2))
486 | (looking-at (rx-to-string `(and ,open-angle (1+ (char "\s\n")) ,close-angle)))
487 | (looking-back (rx-to-string `(and "=" (1+ space) ,open-angle)) line-beg)
488 | (looking-back (rx-to-string `(and "\(" (0+ space) ,open-angle)) line-beg)
489 | (looking-at "\s*$")
490 | (looking-back (rx-to-string `(and line-start (0+ space) ,open-angle)) line-beg)
491 | (looking-back (rx-to-string `(and symbol-start (or "enum" "for" "any" "all" "none")
492 | (0+ space) (opt "\)") (0+ space) ,open-angle)) line-beg)))
493 | (put-text-property quote-beg (1+ quote-beg)
494 | 'syntax-table (string-to-syntax "|"))
495 | (raku-forward-brackets open-angle close-angle angle-length)
496 | (let ((quote-end (- (point) 1)))
497 | (put-text-property quote-beg quote-end 'syntax-multiline t)
498 | (put-text-property quote-end (1+ quote-end)
499 | 'syntax-table (string-to-syntax "|")))))))
500 |
501 | (defun raku-syntax-propertize-backslash ()
502 | (when (eq (raku-syntax-context) nil)
503 | (put-text-property (match-beginning 0) (match-end 0)
504 | 'syntax-table (string-to-syntax "."))))
505 |
506 | (defun raku-add-font-lock-hint (property &optional group)
507 | (let ((beg (match-beginning (or group 1)))
508 | (context (raku-syntax-context)))
509 | (put-text-property beg (1+ beg) property
510 | (cons context (match-data)))))
511 |
512 | (defun raku-syntax-propertize (start end)
513 | "Add context-specific syntax properties to code.
514 |
515 | Takes arguments START and END which delimit the region to propertize."
516 | (let ((case-fold-search nil))
517 | (goto-char start)
518 | (remove-text-properties start end '(raku-metaoperator))
519 | (funcall
520 | (syntax-propertize-rules
521 | ;; [-'] between identifiers are symbol chars
522 | ((rx (regex "[_[:alnum:]]") (group (any "-'")) (regex "[_[:alpha:]]"))
523 | (1 "_"))
524 | ;; same for "::" around identifiers
525 | ((raku-rx (or (and (opt identifier) (group "::") symbol-start)
526 | (and identifier (group "::"))))
527 | (1 "_")
528 | (2 "_"))
529 | ;; pod
530 | ((rx "=begin pod")
531 | (0 (ignore (raku-syntax-propertize-pod end))))
532 | ;; comments
533 | ((rx "#")
534 | (0 (ignore (raku-syntax-propertize-comment end))))
535 | ;; postfix hyper operators
536 | ((raku-rx (or identifier "]" ")") (group (or "»" ">>")))
537 | (0 nil))
538 | ;; other metaoperators like (-), R=>, [*], X~, »+«
539 | ((raku-rx (or set-operator rsxz-operator reduce-operator hyper-operator))
540 | (0 (ignore (raku-add-font-lock-hint 'raku-metaoperator 0))))
541 | ;; angle-bracketed quoting construct
542 | ((rx (or (1+ "<") (1+ "«")))
543 | (0 (ignore (raku-syntax-propertize-angles (match-string 0)))))
544 | ;; backslashes outside strings/comments are punctuation, not escapes
545 | ((rx "\\")
546 | (0 (ignore (raku-syntax-propertize-backslash))))
547 | ;; unicode string quotes
548 | ((rx (any "‘「“"))
549 | (0 (ignore (when (eq (raku-syntax-context) nil)
550 | (backward-char)
551 | (raku-syntax-propertize-delimiters "|")))))
552 | ;; sigils and twigils are prefix characters
553 | ((raku-rx variable)
554 | (1 ". p")
555 | (2 ". p")
556 | ;; go back to the end of the twigils/sigils, so other syntax
557 | ;; rules above can be applied to later parts of the variable name
558 | (4 (ignore (goto-char (or (match-end 2) (match-end 1)))))))
559 | start end)))
560 |
561 | (defun raku-font-lock-syntactic-face (state)
562 | "Specify font lock faces based on syntax table entries.
563 |
564 | Takes STATE, the parse state."
565 | (pcase (raku-syntax-context state)
566 | (`string 'raku-string)
567 | (`comment 'raku-comment)))
568 |
569 | (defun raku-search-when (regex condition limit)
570 | "Search forward for REGEX if the match satisfies CONDITION.
571 |
572 | CONDITION should be a lambda that will be called after REGEX
573 | matches. If CONDITION returns non-nil, this function will set the
574 | match data, then move point forward and return its position, like
575 | `re-search-forward' would.
576 |
577 | If CONDITION returns nil, further searches for REGEX will be
578 | performed until CONDITION returns non-nil or REGEX fails to
579 | match.
580 |
581 | LIMIT can be used to bound the search."
582 | (let ((limit (or limit (point-max)))
583 | (keep-searching t)
584 | (new-match-data))
585 | (save-excursion
586 | (save-match-data
587 | (while keep-searching
588 | (if (re-search-forward regex limit t)
589 | (when (save-excursion (save-match-data (funcall condition)))
590 | (setq new-match-data (match-data)
591 | keep-searching nil))
592 | (setq keep-searching nil)))))
593 | (when new-match-data
594 | (set-match-data new-match-data)
595 | (goto-char (match-end 0)))))
596 |
597 | (defun raku-match-type-constraint (limit)
598 | (raku-search-when
599 | (raku-rx (or (group (symbol type-constraint))
600 | (and (group (symbol "is"))
601 | (1+ space)
602 | (opt (group (symbol type-property))))))
603 | (lambda ()
604 | (goto-char (match-beginning 0))
605 | (and (eq (raku-syntax-context) nil)
606 | (not (looking-back (rx (or (char ".^")
607 | (and line-start (0+ space))))))))
608 | limit))
609 |
610 | (defun raku-match-property (property context limit)
611 | (when (symbolp context)
612 | (setq context (list context)))
613 | (let ((pos (next-single-char-property-change (point) property nil limit)))
614 | (when (> pos (point))
615 | (let ((pos-with-match-data (if (and (= pos (1+ (point)))
616 | (= (point) (point-at-bol))
617 | (not (get-text-property pos property)))
618 | (point)
619 | pos)))
620 | (goto-char pos)
621 | (let ((value (get-text-property pos-with-match-data property)))
622 | (if (and value (memq (car value) context))
623 | (progn (set-match-data (cdr value)) t)
624 | (raku-match-property property context limit)))))))
625 |
626 | (defun raku-match-metaoperator (limit)
627 | (raku-match-property 'raku-metaoperator nil limit))
628 |
629 | (defun raku-match-string-delimiter (limit)
630 | (raku-search-when
631 | (raku-rx (or (syntax string-quote) (syntax string-delimiter)))
632 | (lambda () (not (eq (raku-syntax-context) `comment)))
633 | limit))
634 |
635 | (defconst raku-font-lock-keywords
636 | `(
637 | ;; placeholder sigils
638 | (,(raku-rx (group (any "@$%&"))
639 | (or
640 | "<"
641 | (and (0+ space)
642 | (or (any ",\)\}") (symbol "where")))))
643 | 1 'raku-sigil)
644 | ;; $foo @Bla::Hlagh $.bar $?CLASS
645 | (,(raku-rx variable-mu)
646 | (1 'raku-sigil)
647 | (2 'raku-twigil)
648 | (3 'raku-var-package)
649 | (4 'raku-var-name-mu))
650 | (,(raku-rx variable-positional)
651 | (1 'raku-sigil)
652 | (2 'raku-twigil)
653 | (3 'raku-var-package)
654 | (4 'raku-var-name-positional))
655 | (,(raku-rx variable-associative)
656 | (1 'raku-sigil)
657 | (2 'raku-twigil)
658 | (3 'raku-var-package)
659 | (4 'raku-var-name-associative))
660 | (,(raku-rx variable-callable)
661 | (1 'raku-sigil)
662 | (2 'raku-twigil)
663 | (3 'raku-var-package)
664 | (4 'raku-var-name-callable))
665 | ;; (-) R=> [*] X~ »+«
666 | (raku-match-metaoperator 0 'raku-operator)
667 | ;; v6.0.0
668 | (,(raku-rx symbol-start version) 0 'raku-version)
669 | ;; e.g. $foo is cached
670 | (raku-match-type-constraint
671 | (1 'raku-type-constraint nil t)
672 | (2 'raku-type-constraint nil t)
673 | (3 'raku-type-property nil t))
674 | ;; method calls like $foo.bar or $hlagh.^methods
675 | (,(raku-rx (group (any ".^?")) (group identifier symbol-end))
676 | (1 'raku-operator)
677 | (2 'raku-identifier))
678 | ;; autoquoting fat arrow, foo => $bar
679 | (,(raku-rx (group (symbol identifier)) (1+ space) (group "=>"))
680 | (1 'raku-string)
681 | (2 'raku-operator))
682 | ;; "proto foo", "proto sub foo", etc
683 | (,(raku-rx (group (symbol pre-declare))
684 | (opt (1+ space) (group (symbol declare)))
685 | (opt (1+ space) (group identifier)))
686 | (1 'raku-declare)
687 | (2 'raku-declare nil t)
688 | (3 'raku-identifier nil t))
689 | ;; "sub foo"
690 | (,(raku-rx (group (symbol declare))
691 | (opt (1+ space) (group identifier)))
692 | (1 'raku-declare)
693 | (2 'raku-identifier nil t))
694 | ;; high-level types (Scalar, Class, Str, etc)
695 | (,(raku-rx (group symbol-start high-type) "(") 1 'raku-type)
696 | ;; anything preceding an open-paren is just an identifier
697 | (,(raku-rx (group symbol-start identifier) "(") 1 'raku-identifier)
698 | ;; contextualizers
699 | (,(raku-rx
700 | (or (and (group-n 1 (any "$@%&")) "(")
701 | (group-n 2 (symbol (or "item" "list" "hash")))))
702 | (1 'raku-operator nil t)
703 | (2 'raku-operator nil t))
704 | ;; low-level types (int, bool, complex, etc)
705 | (,(raku-rx (symbol (or low-type high-type))) 0 'raku-type)
706 | ;; adverbs like :foo and :!bar
707 | (,(raku-rx (or bol (regex "[^:]")) (group ":" (opt "!")) (group (symbol identifier)))
708 | (1 'raku-operator)
709 | (2 'raku-string))
710 | ;; div, and, eq...
711 | (,(raku-rx (symbol operator-word)) 0 'raku-operator)
712 | ;; BEGIN, CHECK, INIT...
713 | (,(raku-rx (symbol phaser)) 0 'raku-phaser)
714 | ;; die, fail, try...
715 | (,(raku-rx (symbol exception)) 0 'raku-exception)
716 | ;; let, my, our...
717 | (,(raku-rx (symbol scope)) 0 'raku-scope)
718 | ;; if, else, elsif...
719 | (,(raku-rx (symbol conditional)) 0 'raku-conditional)
720 | ;; use, require...
721 | (,(raku-rx (symbol include)) 0 'raku-include)
722 | ;; for, loop, repeat...
723 | (,(raku-rx (symbol loop)) 0 'raku-loop)
724 | ;; take, do, when...
725 | (,(raku-rx (symbol flow-control)) 0 'raku-flow-control)
726 | ;; oo, fatal...
727 | (,(raku-rx (symbol pragma)) 0 'raku-pragma)
728 | ;; special numbers
729 | (,(raku-rx (symbol (or "Inf" "NaN")))
730 | 0 'raku-number)
731 | ;; block label declarations
732 | (,(raku-rx line-start (0+ space) (group identifier ":") (or space line-end))
733 | 1 'raku-label)
734 | ;; block label references
735 | (,(raku-rx (symbol (or "goto" "next" "last" "redo"))
736 | (1+ space)
737 | (group identifier))
738 | 1 'raku-label)
739 | ;; identifiers with colons
740 | (,(raku-rx
741 | (or symbol-start
742 | (and "::" (group (opt (regex "[?*]")))))
743 | identifier
744 | (opt (0+ "::" identifier))
745 | (opt "::"))
746 | (0 'raku-identifier)
747 | (1 'raku-twigil t t))
748 | ;; numbers
749 | (,(raku-rx (or bol (regex "[^[:digit:]]")) number)
750 | (1 'raku-number)
751 | (2 'raku-number-addition nil t)
752 | (3 'raku-number nil t)
753 | (4 'raku-number-addition nil t))
754 | ;; punctuation operators (+ - : / *, etc)
755 | (,(raku-rx operator-char) 0 'raku-operator)
756 | ;; number with an explicit base (0b010101, 0x1ef1, etc)
757 | (,(raku-rx base-number)
758 | (1 'raku-number)
759 | (2 'raku-number-addition)
760 | (3 'raku-number))
761 | ;; highlight string delimiters as operators
762 | (raku-match-string-delimiter
763 | 0 'raku-operator t))
764 | "Font lock keywords for Raku.")
765 |
766 | (provide 'raku-font-lock)
767 |
768 | ;; Local Variables:
769 | ;; coding: utf-8
770 | ;; indent-tabs-mode: nil
771 | ;; End:
772 |
773 | ;;; raku-font-lock.el ends here
774 |
--------------------------------------------------------------------------------
/raku-imenu.el:
--------------------------------------------------------------------------------
1 | ;;; raku-imenu.el --- Imenu support Raku -*- lexical-binding: t; -*-
2 |
3 | ;; Imenu functions and variables are defined here.
4 |
5 | ;; Definition of "identifiers" (names) from
6 | ;; https://docs.raku.org/language/syntax#Identifiers
7 | ;;
8 | ;; Identifiers are a grammatical building block that occur in several
9 | ;; places. An identifier is a primitive name, and must start with an
10 | ;; alphabetic character (or an underscore), followed by zero or more
11 | ;; word characters (alphabetic, underscore or number). You can also
12 | ;; embed dashes - or single quotes ' in the middle, but not two in a
13 | ;; row, and only if followed immediately by an alphabetic character.
14 | ;;
15 | ;; For NQP names, no embedded hyphens or single quotes are allowed.
16 |
17 | ;; Regex definitions:
18 | (defvar raku-name-regex
19 | (concat
20 | "[_[:alpha:]]" ; mandatory leading character
21 | "\\(?:[-']?[[:alpha:]]" ; rest of the name allowing embedded hyphens or single quotes or '::'
22 | "\\|[_[:alnum:]]"
23 | "\\|\\:\\:[_[:alnum:]]"
24 | "\\)*"
25 | ))
26 |
27 | (defvar nqp-name-regex
28 | (concat
29 | "[_[:alpha:]]" ; mandatory leading character
30 | "[_[:alnum:]]*" ; rest of the name (stricter than Raku name)
31 | ))
32 |
33 | (defvar raku-vars-regex
34 | (concat
35 | "^\\s-*" ; leading ws allowed
36 | "\\(?:my\\|our\\|state\\)\\s-+" ; scope of var, followed by mandatory ws
37 | "\\(" ; start capture group 1 for the var name
38 | "\\(?:\\$\\|@\\|%\\)" ; sigil for type of var
39 | "\\(?:" ; start shy group for choice of one type name
40 | raku-name-regex
41 | "\\|"
42 | nqp-name-regex
43 | "\\)" ; end shy group
44 | "\\)" ; end of capture group 1
45 | ))
46 |
47 | (defvar raku-subs-regex
48 | (concat
49 | "^\\s-*" ; leading ws allowed
50 | "\\(?:my\\s-+\\|our\\s-+\\)?" ; optional specific scope followed by at least one space
51 | ; must have one of the five type identifiers
52 | ; followed by at least one space:
53 | "\\(?:multi\\s-+sub\\|multi\\s-+method\\|sub\\|method\\|multi\\|proto\\)\\s-+"
54 | "\\!?" ; optional private marker
55 | "\\(" ; start capture group 1 for the sub name
56 | raku-name-regex
57 | "\\|"
58 | nqp-name-regex
59 | "\\)" ; end of capture group 1
60 | ))
61 |
62 | (defvar raku-classes-regex
63 | (concat
64 | "^\\s-*" ; leading ws allowed
65 | ; must have one of the four type identifiers followed by at least one space:
66 | "class\\s-+"
67 | "\\(" ; start capture group 1 of the class name
68 | raku-name-regex
69 | "\\|"
70 | nqp-name-regex
71 | "\\)" ; end of capture group 1
72 | ))
73 |
74 | (defvar raku-regexes-regex
75 | (concat
76 | "^\\s-*" ; leading ws allowed
77 | ; must have an identifier followed by at least one space:
78 | "regex\\s-+"
79 | "\\(" ; start capture group 1 of the regex name
80 | raku-name-regex
81 | "\\|"
82 | nqp-name-regex
83 | "\\)" ; end of capture group 1
84 | ))
85 |
86 | (defvar raku-tokens-regex
87 | (concat
88 | "^\\s-*" ; leading ws allowed
89 | ; must have an identifier followed by at least one space:
90 | "token\\s-+"
91 | "\\(" ; start capture group 1 of the regex name
92 | raku-name-regex
93 | "\\|"
94 | nqp-name-regex
95 | "\\)" ; end of capture group 1
96 | ))
97 |
98 | (defvar raku-rules-regex
99 | (concat
100 | "^\\s-*" ; leading ws allowed
101 | ; must have an identifier followed by at least one space:
102 | "rule\\s-+"
103 | "\\(" ; start capture group 1 of the regex name
104 | raku-name-regex
105 | "\\|"
106 | nqp-name-regex
107 | "\\)" ; end of capture group 1
108 | ))
109 |
110 | (defvar raku-grammars-regex
111 | (concat
112 | "^\\s-*" ; leading ws allowed
113 | ; must have an identifier followed by at least one space:
114 | "grammar\\s-+"
115 | "\\(" ; start capture group 1 of the regex name
116 | raku-name-regex
117 | "\\|"
118 | nqp-name-regex
119 | "\\)" ; end of capture group 1
120 | ))
121 |
122 | (defvar raku-imenu-generic-expression
123 | `(
124 | ;; the names are in reverse desired order since they are evaluated here last first
125 | ("Rules" ,raku-rules-regex 1)
126 | ("Tokens" ,raku-tokens-regex 1)
127 | ("Regexes" ,raku-regexes-regex 1)
128 | ("Grammars" ,raku-grammars-regex 1)
129 | ("Classes" ,raku-classes-regex 1)
130 | ("Variables" ,raku-vars-regex 1)
131 | ("Subs/Methods" ,raku-subs-regex 1)
132 | )
133 | "Define interesting points in the Raku buffer for `imenu'.
134 |
135 | This is used to set `imenu-generic-expression' when Raku mode is
136 | entered. Subsequent changes to `raku-imenu-generic-expression' will
137 | not affect existing Raku buffers because imenu-generic-expression is
138 | a local variable.")
139 |
140 | ;;===========================
141 | (provide 'raku-imenu)
142 |
143 | ;; Local Variables:
144 | ;; coding: utf-8
145 | ;; indent-tabs-mode: nil
146 | ;; End:
147 |
148 | ;;; raku-imenu.el ends here
149 |
--------------------------------------------------------------------------------
/raku-indent.el:
--------------------------------------------------------------------------------
1 | ;;; raku-indent.el --- Indentation support Raku -*- lexical-binding: t; -*-
2 |
3 | ;;; Commentary:
4 |
5 | ;; SMIE grammar and various (auto-)indenting functions and variables are
6 | ;; defined here. Currently it's mostly borrowed from css-mode.
7 |
8 | ;;; Code:
9 |
10 | (require 'smie)
11 |
12 | (defconst raku-smie-grammar
13 | (smie-prec2->grammar
14 | (smie-precs->prec2
15 | '((assoc ";") (assoc "=") (assoc ",") (left ":")))))
16 |
17 | (defcustom raku-indent-offset 4
18 | "Basic size of one indentation step."
19 | :type 'integer
20 | :group 'raku)
21 |
22 | (defun raku-smie--not-interpolation-p ()
23 | (save-excursion ;; Prepare for excursion
24 | (forward-char -1) ;; Retreat one char
25 |
26 | (or
27 | ;; Backtrack til we hit something that _isn't_ alnum
28 | ;; If we did not backtrack, we're not in interpolation
29 | (zerop (skip-chars-backward "-[:alnum:]"))
30 |
31 | ;; If we did backtrack, see if #{\$ (EOL) occurs three
32 | ;; or more characters prior to point (??????????)
33 | ;; if this does NOT match, we are not in an interpolation
34 | (not (looking-back "#{\\$" (- (point) 3))))))
35 |
36 | (defun raku-smie--forward-token ()
37 | (cond
38 | ;; Return `;` to fudge end-of-block indentation (I think), as ; is optional after a block
39 | ((and (eq (char-before) ?\}) ;; Character immediately prior to point is `}`
40 | (raku-smie--not-interpolation-p) ;; And, not in an interpolation
41 | ;; FIXME: If the next char is not whitespace, what should we do?
42 | (or (memq (char-after) '(?\s ?\t ?\n)) ;; And, point is followed by \s, \t, or \n
43 | (looking-at comment-start-skip))) ;; or point is looking-at /#+ */
44 |
45 | (if (memq (char-after) '(?\s ?\t ?\n)) ;; If the above is true, and point is followed by /[\s\t\n]/
46 | (forward-char 1) (forward-comment 1)) ;; Then, advance by one character, and one whole comment
47 | ";")
48 |
49 | ((eq (char-after) ?\=) ;; Spit out '=' to kick off proper indentation for hanging assignment
50 | (forward-char 1)
51 | "=")
52 |
53 | ((progn (forward-comment (point-max)) ;; Read past ALL comments
54 | (looking-at "[;,:]")) ;; Are we looking at ; , or :
55 |
56 | (forward-char 1) ;; If so, advance one character
57 | (match-string 0)) ;; And then return whatever looking-at found (?)
58 |
59 | (t (smie-default-forward-token)))) ;; If none of the above matched, defer to SMIE default search
60 |
61 | (defun raku-smie--backward-token ()
62 | (let ((pos (point)))
63 | (forward-comment (- (point))) ;; Retreate past ALL comments up to point
64 | (cond
65 | ;; FIXME: If the next char is not whitespace, what should we do?
66 | ;; Cond #1 - Same end-of-block hack, I think
67 | ((and (eq (char-before) ?\}) ;; Point is preceded immediately by `}`
68 | (raku-smie--not-interpolation-p) ;; And, not in an interpolation
69 | (> pos (point))) ;; And, point has moved backward
70 |
71 | ";") ;; If so, yield ';'
72 |
73 | ((eq (char-before) ?\=)
74 | (forward-char -1)
75 | "=")
76 |
77 | ;; Cond #2 - Get whatever precedes [,:;]
78 | ((memq (char-before) '(?\; ?\, ?\:)) ;; Point is preceded immediately by `;`, `,`, or `:`
79 | (forward-char -1) ;; Retreat one char
80 | (string (char-after))) ;; Return char after point (the char we just retreated past)
81 |
82 | (t (smie-default-backward-token))))) ;; If none of the above matched, defer to SMIE default search
83 |
84 | (defun raku-smie-rules (kind token)
85 | (pcase (cons kind token)
86 | ;; Basic indent offset
87 | (`(:elem . basic) raku-indent-offset)
88 |
89 | ;; Indent offset for function args
90 | (`(:elem . arg) 0)
91 |
92 | (`(:list-intro . ,(or `";" `"")) t) ;"" stands for BOB (bug#15467).
93 |
94 | ;; Make sure that hanging assignment gets indented
95 | (`(:before . "=")
96 | (if (smie-rule-hanging-p)
97 | (smie-rule-parent raku-indent-offset)))
98 |
99 | (`(:before . "{")
100 | (when (smie-rule-hanging-p) ; is `{` the last thing on this line?
101 | (smie-backward-sexp ";") ; y tho
102 | (smie-indent-virtual)))
103 |
104 | (`(:before . ,(or "{" "("))
105 | (if (smie-rule-hanging-p)
106 | (smie-rule-parent 0)))))
107 |
108 | (provide 'raku-indent)
109 |
110 | ;; Local Variables:
111 | ;; coding: utf-8
112 | ;; indent-tabs-mode: nil
113 | ;; End:
114 |
115 | ;;; raku-indent.el ends here
116 |
--------------------------------------------------------------------------------
/raku-mode.el:
--------------------------------------------------------------------------------
1 | ;;; raku-mode.el --- Major mode for editing Raku code -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2015 Hinrik Örn Sigurðsson
4 |
5 | ;; Author: Hinrik Örn Sigurðsson
6 | ;; URL: https://github.com/hinrik/perl6-mode
7 | ;; Keywords: languages
8 | ;; Version: 0.2.1
9 | ;; Package-Requires: ((emacs "24.4"))
10 |
11 | ;; This file is not part of GNU Emacs.
12 |
13 | ;; This program is free software: you can redistribute it and/or modify
14 | ;; it under the terms of the GNU General Public License as published by
15 | ;; the Free Software Foundation, either version 3 of the License, or
16 | ;; (at your option) any later version.
17 |
18 | ;; This program is distributed in the hope that it will be useful,
19 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 | ;; GNU General Public License for more details.
22 |
23 | ;; You should have received a copy of the GNU General Public License
24 | ;; along with this program. If not, see .
25 |
26 | ;;; Commentary:
27 |
28 | ;; GNU Emacs 24 major mode for editing Raku code.
29 |
30 | ;; Currently only provides very basic syntax highlighting.
31 |
32 | ;;; Code:
33 |
34 | (defgroup raku nil
35 | "Major mode for editing Raku code."
36 | :prefix "raku-"
37 | :group 'languages)
38 |
39 | (require 'raku-detect)
40 | (require 'raku-font-lock)
41 | (require 'raku-indent)
42 | (require 'raku-imenu)
43 | (require 'raku-repl)
44 |
45 | (defvar raku-mode-map
46 | (let ((map (make-sparse-keymap)))
47 | (define-key map (kbd "C-c C-l") 'raku-send-line-to-repl)
48 | (define-key map (kbd "C-c C-r") 'raku-send-region-to-repl)
49 | (define-key map (kbd "C-c C-b") 'raku-send-buffer-to-repl)
50 | map)
51 | "Keymap for `raku-mode'.")
52 |
53 | (easy-menu-define raku-mode-menu raku-mode-map
54 | "Menu for `raku-mode'"
55 | '("Raku"
56 | ["Send line to repl" raku-send-line-to-repl]
57 | ["Send region to repl" raku-send-region-to-repl]
58 | ["Send buffer to repl" raku-send-buffer-to-repl]))
59 |
60 | ;;;###autoload
61 | (define-derived-mode raku-mode prog-mode "Raku"
62 | "Major mode for editing Raku code."
63 | ;; Syntaxification and font locking
64 | (setq-local syntax-propertize-function #'raku-syntax-propertize)
65 | (add-hook 'syntax-propertize-extend-region-functions #'syntax-propertize-multiline nil 'local)
66 | (setq-local font-lock-syntactic-face-function #'raku-font-lock-syntactic-face)
67 | (setq-local font-lock-defaults '(raku-font-lock-keywords nil nil))
68 | ;; Add imenu support for raku-mode. Note that imenu-generic-expression
69 | ;; is buffer-local, so we don't need a local-variable for it.
70 | (add-hook 'raku-mode-hook 'imenu-add-menubar-index)
71 | (setq imenu-generic-expression raku-imenu-generic-expression
72 | imenu-case-fold-search nil)
73 | ;; Comments
74 | (setq-local comment-start "#")
75 | (setq-local comment-start-skip "#+ *")
76 | (setq-local comment-use-syntax t)
77 | (setq-local comment-end "")
78 | ;; Indentation (see SMIE in the Emacs manual)
79 | ;; TODO add rules for HEREDOC indentation
80 | (smie-setup raku-smie-grammar #'raku-smie-rules
81 | :forward-token #'raku-smie--forward-token
82 | :backward-token #'raku-smie--backward-token)
83 | (use-local-map raku-mode-map))
84 |
85 | (defalias 'perl6-mode 'raku-mode)
86 |
87 | (provide 'raku-mode)
88 |
89 | ;; Local Variables:
90 | ;; coding: utf-8
91 | ;; indent-tabs-mode: nil
92 | ;; End:
93 |
94 | ;;; raku-mode.el ends here
95 |
--------------------------------------------------------------------------------
/raku-repl.el:
--------------------------------------------------------------------------------
1 | ;;; raku-repl -- Repl for support Raku
2 |
3 | ;;; Commentary:
4 | ;; Basic repl support for Raku
5 |
6 | ;;; Code:
7 | (require 'comint)
8 | (require 'raku-font-lock)
9 |
10 | (defcustom raku-exec-path "raku"
11 | "Raku executable path."
12 | :type 'string
13 | :group 'raku)
14 |
15 | (defcustom raku-exec-arguments ""
16 | "Raku command line arguments."
17 | :type 'string
18 | :group 'raku)
19 |
20 | (defvar raku-prompt-regexp "^> "
21 | "Prompt for `run-raku'.")
22 |
23 | (defvar raku-buffer-name "Raku REPL"
24 | "Buffer name for `run-raku.")
25 |
26 | (define-derived-mode raku-repl-mode comint-mode "Raku"
27 | "Major mode for `run-raku'."
28 | ;; Set up the prompt and make it read only.
29 | (setq-local comint-prompt-regexp raku-prompt-regexp)
30 | (setq-local comint-prompt-readonly t)
31 | ;; See raku-mode.el.
32 | (setq-local syntax-propertize-function #'raku-syntax-propertize)
33 | (add-hook 'syntax-propertize-extend-region-functions #'syntax-propertize-multiline nil 'local)
34 | (setq-local font-lock-syntactic-face-function #'raku-font-lock-syntactic-face)
35 | (setq-local font-lock-defaults '(raku-font-lock-keywords nil nil))
36 | (add-hook 'raku-mode-hook 'imenu-add-menubar-index)
37 | (setq imenu-generic-expression raku-imenu-generic-expression
38 | imenu-case-fold-search nil)
39 | (setq-local comment-start "#")
40 | (setq-local comment-start-skip "#+ *")
41 | (setq-local comment-use-syntax t)
42 | (setq-local comment-end "")
43 | ;; Don't jump beyond the prompt with M-{ or M-}.
44 | (setq-local paragraph-start raku-prompt-regexp))
45 |
46 | (defun run-raku ()
47 | "Run an inferior instance of `raku' inside Emacs."
48 | (interactive)
49 | (let* ((raku-program raku-exec-path)
50 | (check-proc (comint-check-proc raku-buffer-name))
51 | (buffer (apply 'make-comint-in-buffer
52 | raku-buffer-name
53 | check-proc
54 | raku-exec-path
55 | '()
56 | (split-string raku-exec-arguments))))
57 | (with-current-buffer buffer
58 | (raku-repl-mode))
59 | (display-buffer buffer)))
60 |
61 | (defun raku-comint-get-process ()
62 | "Raku process name."
63 | (get-process raku-buffer-name))
64 |
65 | (defun raku-send-string-to-repl (str)
66 | "Send STR to the repl."
67 | (comint-send-string (raku-comint-get-process)
68 | (concat str "\n")))
69 |
70 | (defun raku-send-line-to-repl ()
71 | "Send a line to the repl."
72 | (interactive)
73 | (run-raku)
74 | (let ((str (buffer-substring-no-properties (line-beginning-position) (line-end-position))))
75 | (raku-send-string-to-repl str)))
76 |
77 | (defun raku-send-region-to-repl ()
78 | "Send a region to the repl."
79 | (interactive)
80 | (run-raku)
81 | (if (region-active-p)
82 | (let ((buf (buffer-substring-no-properties (region-beginning)
83 | (region-end))))
84 | (raku-send-string-to-repl buf))
85 | (message "No region selected")))
86 |
87 | (defun raku-send-buffer-to-repl ()
88 | "Send a buffer to the repl."
89 | (interactive)
90 | (run-raku)
91 | (let ((buf (buffer-substring-no-properties (point-min)
92 | (point-max))))
93 | (raku-send-string-to-repl buf)))
94 |
95 | (provide 'raku-repl)
96 | ;;; raku-repl.el ends here
97 |
--------------------------------------------------------------------------------
/raku-skeletons.el:
--------------------------------------------------------------------------------
1 | ;;; raku-skeletons.el --- Skeletons for Raku file auto insertion. -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2020 Tim Van den Langenbergh
4 |
5 | ;; Author: Tim Van den Langenbergh
6 | ;; URL: https://github.com/raku/raku-mode
7 | ;; Keywords: languages, convenience, files
8 | ;; Version: 0.1
9 |
10 | ;; This program is free software; you can redistribute it and/or modify
11 | ;; it under the terms of the GNU General Public License as published by
12 | ;; the Free Software Foundation, either version 3 of the License, or
13 | ;; (at your option) any later version.
14 |
15 | ;; This program is distributed in the hope that it will be useful,
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | ;; GNU General Public License for more details.
19 |
20 | ;; You should have received a copy of the GNU General Public License
21 | ;; along with this program. If not, see .
22 |
23 | ;;; Commentary:
24 |
25 | ;; Some skeletons for auto-insertion in Raku files.
26 |
27 | ;;; Code:
28 | (require 'raku-mode)
29 |
30 | (defgroup raku-skeletons nil
31 | "Skeletons for Raku files."
32 | :prefix "raku-skeleton-"
33 | :group 'raku)
34 |
35 | ;; Need the full path for the #!. Simply setting it to `raku' may not be ideal.
36 | (defcustom full-raku-path "/usr/bin/env raku"
37 | "Path to the Raku executable."
38 | :type 'string
39 | :group 'raku-skeletons)
40 |
41 | ;; A string for `:auth';
42 | (defcustom auth-id user-login-name
43 | "Module author information."
44 | :type 'string
45 | :group 'raku-skeletons)
46 |
47 | (define-skeleton raku-script-skeleton
48 | "Skeleton for Raku scripts."
49 | nil
50 | "#!" (progn full-raku-path) \n
51 | "use v6;" \n
52 | \n
53 | "sub MAIN () {" \n
54 | > _ \n
55 | "}" \n)
56 |
57 | (defvar module-name "Foo"
58 | "Variable for holding a new module name.")
59 |
60 | (define-skeleton raku-module-skeleton
61 | "Skeleton for Raku modules."
62 | nil
63 | "use v6;" \n
64 | \n
65 | "unit module "
66 | (let ((given-name (skeleton-read "Module name: " module-name)))
67 | (setq module-name given-name)
68 | given-name)
69 | ":ver<0.0.1>:auth<" (progn auth-id) ">;" \n
70 | \n
71 | _ \n
72 | \n
73 | "=begin pod" \n
74 | \n
75 | "=head1 NAME" \n
76 | \n
77 | (progn module-name) " - " (skeleton-read "Short description: ") \n
78 | \n
79 | "=head1 SYNOPSIS" \n
80 | \n
81 | "\tuse " (progn module-name) ";\n"
82 | \n
83 | "=head1 DESCRIPTION" \n
84 | \n
85 | (progn module-name) " is..." \n
86 | \n
87 | "=head1 AUTHOR" \n
88 | \n
89 | (progn auth-id) \n
90 | \n
91 | "=head1 COPYRIGHT AND LICENSE" \n
92 | \n
93 | "This library is free software; "
94 | "you can redistribute it and/or modify it under the Artistic License 2.0."
95 | "\n\n"
96 | "=end pod" \n)
97 |
98 | ;; TODO: Maybe META6.json and .t/.rakutest skeletons?
99 |
100 | (provide 'raku-skeletons)
101 | ;;; raku-skeletons.el ends here
102 |
--------------------------------------------------------------------------------
/raku-unicode-menu.el:
--------------------------------------------------------------------------------
1 | ;; Provide a menu bar item to ease insertion of Unicode characters.
2 |
3 |
4 | ;; Make a menu keymap (with a prompt string)
5 | ;; and make it the menu bar item’s definition.
6 | ;; put it at the end
7 | (define-key global-map [menu-bar unicode]
8 | (cons "Unicode" (make-sparse-keymap "Unicode")))
9 | ;; Define specific subcommands in this menu.
10 | (define-key global-map
11 | [menu-bar unicode forward]
12 | '("Forward word" . forward-word))
13 | (define-key global-map
14 | [menu-bar unicode backward]
15 | '("Backward word" . backward-word))
16 | (defvar menu-bar-final-items '(help-menu unicode-menu)) ;; doesn't work??
17 |
18 |
19 |
20 |
21 |
22 | ;;===========================
23 | (provide 'raku-unicode-menu)
24 |
25 | ;; Local Variables:
26 | ;; coding: utf-8
27 | ;; indent-tabs-mode: nil
28 | ;; End:
29 |
30 | ;;; raku-imenu.el ends here
31 |
--------------------------------------------------------------------------------
/test/raku-mode-test.el:
--------------------------------------------------------------------------------
1 | ;;; raku-mode-test.el --- Raku Mode: Unit test suite -*- lexical-binding: t; -*-
2 |
3 | ;;; Commentary:
4 |
5 | ;; The unit test suite of Raku Mode.
6 |
7 | ;;; Code:
8 |
9 | (require 'raku-mode)
10 | (require 'ert)
11 |
12 |
13 | ;;;; Utilities
14 |
15 | (defmacro raku-test-with-temp-buffer (content &rest body)
16 | "In the temporary buffer CONTENT, evaluate BODY."
17 | (declare (debug t)
18 | (indent 1))
19 | `(with-temp-buffer
20 | (insert ,content)
21 | (raku-mode)
22 | (font-lock-fontify-buffer)
23 | (goto-char (point-min))
24 | ,@body))
25 |
26 | (defun raku-test-face-at (pos &optional content)
27 | "Get the face at POS in CONTENT.
28 |
29 | If CONTENT is not given, return the face at POS in the current
30 | buffer."
31 | (if content
32 | (raku-test-with-temp-buffer content
33 | (get-text-property pos 'face))
34 | (get-text-property pos 'face)))
35 |
36 | (defconst raku-test-syntax-classes
37 | [whitespace punctuation word symbol open-paren close-paren expression-prefix
38 | string-quote paired-delim escape character-quote comment-start
39 | comment-end inherit generic-comment generic-string]
40 | "Readable symbols for syntax classes.
41 |
42 | Each symbol in this vector corresponding to the syntax code of
43 | its index.")
44 |
45 | (defun raku-test-syntax-at (pos)
46 | "Get the syntax at POS.
47 |
48 | Get the syntax class symbol at POS, or nil if there is no syntax a
49 | POS."
50 | (let ((code (syntax-class (syntax-after pos))))
51 | (aref raku-test-syntax-classes code)))
52 |
53 |
54 | ;;;; Font locking
55 | (ert-deftest raku-syntax-propertize/colons-identifier ()
56 | :tags '(syntax-table syntax-properties)
57 | (raku-test-with-temp-buffer "class Foo::Bar"
58 | (should (eq (raku-test-syntax-at 10) 'symbol))
59 | (should (eq (raku-test-syntax-at 11) 'symbol))))
60 |
61 | (ert-deftest raku-syntax-propertize/angles ()
62 | :tags '(syntax-table syntax-properties)
63 | (raku-test-with-temp-buffer "my @foo = ; for @foo <-> $bar {}"
64 | (should (eq (raku-test-syntax-at 11) 'generic-string))
65 | (should (eq (raku-test-syntax-at 15) 'generic-string))
66 | (should (eq (raku-test-syntax-at 27) 'punctuation))
67 | (should (eq (raku-test-syntax-at 29) 'punctuation))))
68 |
69 | (ert-deftest raku-syntax-propertize/dq-words ()
70 | :tags '(syntax-table syntax-properties)
71 | (raku-test-with-temp-buffer "foo «bar1 bar2» bla <> quux"
72 | (should (eq (raku-test-syntax-at 1) 'word))
73 | (should (eq (raku-test-syntax-at 5) 'generic-string))
74 | (should (eq (raku-test-syntax-at 15) 'generic-string))
75 | (should (eq (raku-test-syntax-at 21) 'generic-string))
76 | (should (eq (raku-test-syntax-at 22) 'punctuation))
77 | (should (eq (raku-test-syntax-at 32) 'punctuation))
78 | (should (eq (raku-test-syntax-at 33) 'generic-string))))
79 |
80 | (ert-deftest raku-mode-syntax-table/fontify-dq-string ()
81 | :tags '(fontification syntax-table)
82 | (should (eq (raku-test-face-at 9 "$foo = \"bar\"") 'raku-string)))
83 |
84 | (ert-deftest raku-mode-syntax-table/fontify-set-operator ()
85 | :tags '(fontification syntax-table)
86 | (should (eq (raku-test-face-at 6 "$mh (<+) $m") 'raku-operator)))
87 |
88 | (ert-deftest raku-mode-syntax-table/fontify-sq-string ()
89 | :tags '(fontification syntax-table)
90 | (should (eq (raku-test-face-at 9 "$foo = 'bar'") 'raku-string)))
91 |
92 | (ert-deftest raku-mode-syntax-table/fontify-line-comment ()
93 | :tags '(fontification syntax-table)
94 | (raku-test-with-temp-buffer "# class
95 | bar #` baz"
96 | (should (eq (raku-test-face-at 3) 'raku-comment))
97 | (should (eq (raku-test-face-at 7) 'raku-comment))
98 | (should (eq (raku-test-face-at 8) 'raku-comment))
99 | (should (eq (raku-test-face-at 9) 'raku-identifier))
100 | (should (eq (raku-test-face-at 16) 'raku-comment))))
101 |
102 | (ert-deftest raku-font-lock-keywords/phaser ()
103 | :tags '(fontification font-lock-keywords)
104 | (raku-test-with-temp-buffer "BEGIN {"
105 | (should (eq (raku-test-face-at 1) 'raku-phaser))))
106 |
107 | (ert-deftest perl5-font-lock-keywords/variable ()
108 | :tags '(fontification syntax-table)
109 | (raku-test-with-temp-buffer "$::foo @!bar"
110 | (should (eq (raku-test-face-at 3) 'raku-var-package))
111 | (should (eq (raku-test-face-at 4) 'raku-var-name))
112 | (should (eq (raku-test-face-at 8) 'raku-sigil))
113 | (should (eq (raku-test-face-at 9) 'raku-twigil))
114 | (should (eq (raku-test-face-at 10) 'raku-var-name))))
115 |
116 | (provide 'raku-mode-test)
117 |
118 | ;; Local Variables:
119 | ;; indent-tabs-mode: nil
120 | ;; End:
121 |
122 | ;;; raku-mode-test.el ends here
123 |
--------------------------------------------------------------------------------
/test/test-helper.el:
--------------------------------------------------------------------------------
1 | ;;; test-helper.el --- Raku Mode: Non-interactive unit-test setup -*- lexical-binding: t; -*-
2 |
3 | ;;; Commentary:
4 |
5 | ;; Non-interactive test suite setup for ERT Runner.
6 |
7 | ;;; Code:
8 |
9 | (message "Running tests on Emacs %s" emacs-version)
10 |
11 | (let* ((current-file (if load-in-progress load-file-name (buffer-file-name)))
12 | (source-directory (locate-dominating-file current-file "Cask"))
13 | ;; Do not load outdated byte code for tests
14 | (load-prefer-newer t))
15 | ;; Load the file under test
16 | (add-to-list 'load-path source-directory)
17 | (load (expand-file-name "raku-mode")))
18 |
19 | ;; Local Variables:
20 | ;; indent-tabs-mode: nil
21 | ;; End:
22 |
23 | ;;; test-helper.el ends here
24 |
--------------------------------------------------------------------------------
/test/test-imenu.nqp:
--------------------------------------------------------------------------------
1 | # file: test-imenu.p6
2 |
3 | # Raku syntax file for testing raku-mode with imenu support, which is located at:
4 | #
5 | # https://github.com/tbrowder/raku-mode [branch: "my-branch"]
6 |
7 | my $a;
8 | my @b;
9 | our %c;
10 |
11 | my $a-a;
12 | my $a'a_3-z;
13 |
14 | sub a(){my @ze}
15 | multi sub x() {}
16 | method d() {}
17 | my multi method z() {}
18 | multi c() {}
19 |
20 | proto xx() {}
21 |
22 | class My-class1 {}
23 | class My-class2{
24 | class doit () {}
25 |
--------------------------------------------------------------------------------
/test/test-imenu.p6:
--------------------------------------------------------------------------------
1 | # file: test-imenu.p6
2 |
3 | # Raku syntax file for testing raku-mode with imenu support, which
4 | # is located at:
5 | #
6 | # https://github.com/tbrowder/raku-mode [branch: "my-branch"]
7 |
8 | my $a;
9 | my @b;
10 | our %c;
11 |
12 | my $a-a;
13 | my $a'a_3-z;
14 |
15 | state $ds;
16 | sub a(){my @ze}
17 | multi sub x() {}
18 | method d() {}
19 | my multi method z() {}
20 | multi c() {}
21 | proto xx() {}
22 | multi method !z-private() {}
23 |
24 | my $F::B;
25 |
26 | class My-class1 {}
27 | class My-class2{
28 | class doit () {}
29 |
30 | token one {}
31 | regex two {}
32 | rule three {}
33 | grammar G::T {}
34 |
--------------------------------------------------------------------------------
/test/test-smie.p6:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env raku
2 | qq:to/HERE/;
3 | This is text that should not
4 | have its indention changed
5 | by emacs. (Except maybe to have left overhanging lines
6 | adjusted.)
7 | HERE
8 |
9 | my %var =
10 | A => 1,
11 | :b<2>,
12 | :3c,
13 | D => 4;
14 |
--------------------------------------------------------------------------------