source: trunk/abcl/contrib/named-readtables/README.md

Last change on this file was 15019, checked in by Mark Evenson, 7 years ago

abcl-contrib: add NAMED-READTABLES

From <https://github.com/melisgl/named-readtables>.

c.f. <https://github.com/melisgl/named-readtables/issues/10>

File size: 18.2 KB
Line 
1<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-MANUAL-20MGL-PAX-3ASECTION-29'></a>
2
3# Named Readtables Manual
4
5## Table of Contents
6
7- [1 named-readtables ASDF System Details][9b5b]
8- [2 Introduction][6faf]
9    - [2.1 Links][8688]
10    - [2.2 Acknowledgements][059d]
11- [3 Overview][0bc2]
12    - [3.1 Notes on the API][e4cd]
13    - [3.2 Important API idiosyncrasies][62b8]
14    - [3.3 Preregistered Readtables][58c6]
15    - [3.4 Examples][cf94]
16- [4 Reference][373d]
17
18###### \[in package EDITOR-HINTS.NAMED-READTABLES\]
19<a name='x-28-22named-readtables-22-20ASDF-2FSYSTEM-3ASYSTEM-29'></a>
20
21## 1 named-readtables ASDF System Details
22
23- Version: 0.9
24- Description: Library that creates a namespace for named readtable
25  akin to the namespace of packages.
26- Licence: BSD, see LICENSE
27- Author: Tobias C. Rittweiler <trittweiler@common-lisp.net>
28- Maintainer: Gábor Melis
29- Mailto: [mega@retes.hu](mailto:mega@retes.hu)
30
31<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-INTRODUCTION-20MGL-PAX-3ASECTION-29'></a>
32
33## 2 Introduction
34
35Named-Readtables is a library that provides a namespace for
36readtables akin to the already-existing namespace of packages. In
37particular:
38
39- you can associate readtables with names, and retrieve
40  readtables by names;
41
42- you can associate source files with readtable names, and be
43  sure that the right readtable is active when compiling/loading
44  the file;
45
46- similiarly, your development environment now has a chance to
47  automatically determine what readtable should be active while
48  processing source forms on interactive commands. (E.g. think of
49  `C-c C-c` in Slime (yet to be done))
50
51It follows that Named-Readtables is a facility for using readtables in
52a localized way.
53
54Additionally, it also attempts to become a facility for using
55readtables in a *modular* way. In particular:
56
57- it provides a macro to specify the content of a readtable at a
58 glance;
59
60- it makes it possible to use multiple inheritance between readtables.
61
62
63<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-LINKS-20MGL-PAX-3ASECTION-29'></a>
64
65### 2.1 Links
66
67Here is the [official repository][named-readtables-repo] and the
68[HTML documentation][named-readtables-doc] for the latest version.
69
70[named-readtables-repo]: https://github.com/melisgl/named-readtables
71
72[named-readtables-doc]: http://melisgl.github.io/mgl-pax-world/named-readtables-manual.html
73
74
75<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-ACKNOWLEDGEMENTS-20MGL-PAX-3ASECTION-29'></a>
76
77### 2.2 Acknowledgements
78
79Thanks to Robert Goldman for making me want to write this library.
80
81Thanks to Stephen Compall, Ariel Badichi, David Lichteblau, Bart
82Botta, David Crawford, and Pascal Costanza for being early adopters,
83providing comments and bugfixes.
84
85<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-OVERVIEW-20MGL-PAX-3ASECTION-29'></a>
86
87## 3 Overview
88
89<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-API-NOTES-20MGL-PAX-3ASECTION-29'></a>
90
91### 3.1 Notes on the API
92
93The API heavily imitates the API of packages. This has the nice
94property that any experienced Common Lisper will take it up without
95effort.
96
97    DEFREADTABLE              -   DEFPACKAGE
98   
99    IN-READTABLE              -   IN-PACKAGE
100   
101    MERGE-READTABLES-INTO     -   USE-PACKAGE
102   
103    MAKE-READTABLE            -   MAKE-PACKAGE
104   
105    UNREGISTER-READTABLE      -   DELETE-PACKAGE
106   
107    RENAME-READTABLE          -   RENAME-PACKAGE
108   
109    FIND-READTABLE            -   FIND-PACKAGE
110   
111    READTABLE-NAME            -   PACKAGE-NAME
112   
113    LIST-ALL-NAMED-READTABLES -   LIST-ALL-PACKAGES
114
115
116<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-API-IDIOSYNCRASIES-20MGL-PAX-3ASECTION-29'></a>
117
118### 3.2 Important API idiosyncrasies
119
120There are three major differences between the API of Named-Readtables,
121and the API of packages.
122
1231. Readtable names are symbols not strings.
124
125    Time has shown that the fact that packages are named by strings
126    causes severe headache because of the potential of package names
127    colliding with each other.
128
129    Hence, readtables are named by symbols lest to make the
130    situation worse than it already is. Consequently, readtables
131    named `CL-ORACLE:SQL-SYNTAX` and `CL-MYSQL:SQL-SYNTAX` can
132    happily coexist next to each other. Or, taken to an extreme,
133    `SCHEME:SYNTAX` and `ELISP:SYNTAX`.
134
135    If, for example to duly signify the importance of your cool
136    readtable hack, you really think it deserves a global name, you
137    can always resort to keywords.
138
1392. The inheritance is resolved statically, not dynamically.
140
141    A package that uses another package will have access to all the
142    other package's exported symbols, even to those that will be
143    added after its definition. I.e. the inheritance is resolved at
144    run-time, that is dynamically.
145
146    Unfortunately, we cannot do the same for readtables in a
147    portable manner.
148
149    Therefore, we do not talk about "using" another readtable but
150    about "merging" the other readtable's definition into the
151    readtable we are going to define. I.e. the inheritance is
152    resolved once at definition time, that is statically.
153
154    (Such merging can more or less be implemented portably albeit at
155    a certain cost. Most of the time, this cost manifests itself at
156    the time a readtable is defined, i.e. once at compile-time, so
157    it may not bother you. Nonetheless, we provide extra support for
158    Sbcl, ClozureCL, and AllegroCL at the moment. Patches for your
159    implementation of choice are welcome, of course.)
160
1613. [`DEFREADTABLE`][8b94] does not have compile-time effects.
162
163    If you define a package via `DEFPACKAGE`, you can make that
164    package the currently active package for the subsequent
165    compilation of the same file via `IN-PACKAGE`. The same is,
166    however, not true for [`DEFREADTABLE`][8b94] and [`IN-READTABLE`][de3b] for the
167    following reason:
168
169    It's unlikely that the need for special reader-macros arises for
170    a problem which can be solved in just one file. Most often,
171    you're going to define the reader macro functions, and set up
172    the corresponding readtable in an extra file.
173
174    If [`DEFREADTABLE`][8b94] had compile-time effects, you'd have to wrap
175    each definition of a reader-macro function in an `EVAL-WHEN` to
176    make its definition available at compile-time. Because that's
177    simply not the common case, [`DEFREADTABLE`][8b94] does not have a
178    compile-time effect.
179
180    If you want to use a readtable within the same file as its
181    definition, wrap the [`DEFREADTABLE`][8b94] and the reader-macro function
182    definitions in an explicit `EVAL-WHEN`.
183
184
185<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-PREREGISTERED-20MGL-PAX-3ASECTION-29'></a>
186
187### 3.3 Preregistered Readtables
188
189- `NIL`, `:STANDARD`, and `:COMMON-LISP` designate the
190*standard readtable*.
191
192- `:MODERN` designates a *case-preserving* *standard-readtable*.
193
194- `:CURRENT` designates the *current readtable*.
195
196
197<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-EXAMPLES-20MGL-PAX-3ASECTION-29'></a>
198
199### 3.4 Examples
200
201```commonlisp
202(defreadtable elisp:syntax
203   (:merge :standard)
204   (:macro-char #\? #'elisp::read-character-literal t)
205   (:macro-char #\[ #'elisp::read-vector-literal t)
206   ...
207   (:case :preserve))
208
209(defreadtable scheme:syntax
210   (:merge :standard)
211   (:macro-char #\[ #'(lambda (stream char)
212                         (read-delimited-list #\] stream)))
213   (:macro-char #\# :dispatch)
214   (:dispatch-macro-char #\# #\t #'scheme::read-#t)
215   (:dispatch-macro-char #\# #\f #'scheme::read-#f)
216   ...
217   (:case :preserve))
218
219(in-readtable elisp:syntax)
220
221...
222
223(in-readtable scheme:syntax)
224
225...
226```
227
228
229<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-REFERENCE-20MGL-PAX-3ASECTION-29'></a>
230
231## 4 Reference
232
233<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3ADEFREADTABLE-20-28MGL-PAX-3AMACRO-29-29'></a>
234
235- [macro] **DEFREADTABLE** *NAME &BODY OPTIONS*
236
237    Define a new named readtable, whose name is given by the symbol `NAME`.
238    Or, if a readtable is already registered under that name, redefine
239    that one.
240   
241    The readtable can be populated using the following `OPTIONS`:
242   
243    - `(:MERGE READTABLE-DESIGNATORS+)`
244   
245        Merge the readtables designated into the new readtable being
246        defined as per [`MERGE-READTABLES-INTO`][77fa].
247   
248        If no `:MERGE` clause is given, an empty readtable is used. See
249        [`MAKE-READTABLE`][958e].
250   
251    - `(:FUSE READTABLE-DESIGNATORS+)`
252   
253        Like `:MERGE` except:
254   
255        Error conditions of type [`READER-MACRO-CONFLICT`][acb7] that are signaled
256        during the merge operation will be silently *continued*. It
257        follows that reader macros in earlier entries will be
258        overwritten by later ones. For backward compatibility, `:FUZE` is
259        accepted as an alias of `:FUSE`.
260   
261    - `(:DISPATCH-MACRO-CHAR MACRO-CHAR SUB-CHAR FUNCTION)`
262   
263        Define a new sub character `SUB-CHAR` for the dispatching macro
264        character `MACRO-CHAR`, per `SET-DISPATCH-MACRO-CHARACTER`. You
265        probably have to define `MACRO-CHAR` as a dispatching macro
266        character by the following option first.
267   
268    - `(:MACRO-CHAR MACRO-CHAR FUNCTION [NON-TERMINATING-P])`
269   
270        Define a new macro character in the readtable, per
271        `SET-MACRO-CHARACTER`. If `FUNCTION` is the keyword `:DISPATCH`,
272        `MACRO-CHAR` is made a dispatching macro character, per
273        `MAKE-DISPATCH-MACRO-CHARACTER`.
274   
275    - `(:SYNTAX-FROM FROM-READTABLE-DESIGNATOR FROM-CHAR TO-CHAR)`
276   
277        Set the character syntax of `TO-CHAR` in the readtable being
278        defined to the same syntax as `FROM-CHAR` as per
279        `SET-SYNTAX-FROM-CHAR`.
280   
281    - `(:CASE CASE-MODE)`
282   
283        Defines the *case sensitivity mode* of the resulting readtable.
284   
285    Any number of option clauses may appear. The options are grouped by
286    their type, but in each group the order the options appeared
287    textually is preserved. The following groups exist and are executed
288    in the following order: `:MERGE` and `:FUSE` (one
289    group), `:CASE`, `:MACRO-CHAR` and `:DISPATCH-MACRO-CHAR` (one group),
290    finally `:SYNTAX-FROM`.
291   
292    Notes:
293   
294    The readtable is defined at load-time. If you want to have it
295    available at compilation time -- say to use its reader-macros in the
296    same file as its definition -- you have to wrap the [`DEFREADTABLE`][8b94]
297    form in an explicit `EVAL-WHEN`.
298   
299    On redefinition, the target readtable is made empty first before
300    it's refilled according to the clauses.
301   
302    `NIL`, `:STANDARD`, `:COMMON-LISP`, `:MODERN`, and `:CURRENT` are
303    preregistered readtable names.
304
305<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3AIN-READTABLE-20-28MGL-PAX-3AMACRO-29-29'></a>
306
307- [macro] **IN-READTABLE** *NAME*
308
309    Set `*READTABLE*` to the readtable referred to by the symbol `NAME`.
310
311<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3AMAKE-READTABLE-20FUNCTION-29'></a>
312
313- [function] **MAKE-READTABLE** *&OPTIONAL (NAME NIL NAME-SUPPLIED-P) &KEY MERGE*
314
315    Creates and returns a new readtable under the specified
316    `NAME`.
317   
318    `MERGE` takes a list of NAMED-READTABLE-DESIGNATORS and specifies the
319    readtables the new readtable is created from. (See the `:MERGE` clause
320    of [`DEFREADTABLE`][8b94] for details.)
321   
322    If `MERGE` is `NIL`, an empty readtable is used instead.
323   
324    If `NAME` is not given, an anonymous empty readtable is returned.
325   
326    Notes:
327   
328    An empty readtable is a readtable where each character's syntax is
329    the same as in the *standard readtable* except that each macro
330    character has been made a constituent. Basically: whitespace stays
331    whitespace, everything else is constituent.
332
333<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3AMERGE-READTABLES-INTO-20FUNCTION-29'></a>
334
335- [function] **MERGE-READTABLES-INTO** *RESULT-READTABLE &REST NAMED-READTABLES*
336
337    Copy the contents of each readtable in `NAMED-READTABLES`([`0`][] [`1`][9b5b]) into
338    `RESULT-READTABLE`.
339   
340    If a macro character appears in more than one of the readtables,
341    i.e. if a conflict is discovered during the merge, an error of type
342    [`READER-MACRO-CONFLICT`][acb7] is signaled.
343
344<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3AFIND-READTABLE-20FUNCTION-29'></a>
345
346- [function] **FIND-READTABLE** *NAME*
347
348    Looks for the readtable specified by `NAME` and returns it if it is
349    found. Returns `NIL` otherwise.
350
351<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3AENSURE-READTABLE-20FUNCTION-29'></a>
352
353- [function] **ENSURE-READTABLE** *NAME &OPTIONAL (DEFAULT NIL DEFAULT-P)*
354
355    Looks up the readtable specified by `NAME` and returns it if it's found.
356    If it is not found, it registers the readtable designated by `DEFAULT`
357    under the name represented by NAME; or if no default argument is
358    given, it signals an error of type [`READTABLE-DOES-NOT-EXIST`][437a]
359    instead.
360
361<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3ARENAME-READTABLE-20FUNCTION-29'></a>
362
363- [function] **RENAME-READTABLE** *OLD-NAME NEW-NAME*
364
365    Replaces the associated name of the readtable designated by
366    `OLD-NAME` with `NEW-NAME`. If a readtable is already registered under
367    `NEW-NAME`, an error of type [`READTABLE-DOES-ALREADY-EXIST`][4b51] is
368    signaled.
369
370<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3AREADTABLE-NAME-20FUNCTION-29'></a>
371
372- [function] **READTABLE-NAME** *NAMED-READTABLE*
373
374    Returns the name of the readtable designated by `NAMED-READTABLE`,
375    or `NIL`.
376
377<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3AREGISTER-READTABLE-20FUNCTION-29'></a>
378
379- [function] **REGISTER-READTABLE** *NAME READTABLE*
380
381    Associate `READTABLE` with `NAME`. Returns the readtable.
382
383<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3AUNREGISTER-READTABLE-20FUNCTION-29'></a>
384
385- [function] **UNREGISTER-READTABLE** *NAMED-READTABLE*
386
387    Remove the association of `NAMED-READTABLE`. Returns `T` if successfull,
388    `NIL` otherwise.
389
390<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3ACOPY-NAMED-READTABLE-20FUNCTION-29'></a>
391
392- [function] **COPY-NAMED-READTABLE** *NAMED-READTABLE*
393
394    Like `COPY-READTABLE` but takes a [`NAMED-READTABLE-DESIGNATOR`][fa0c] as argument.
395
396<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3ALIST-ALL-NAMED-READTABLES-20FUNCTION-29'></a>
397
398- [function] **LIST-ALL-NAMED-READTABLES**
399
400    Returns a list of all registered readtables. The returned list is
401    guaranteed to be fresh, but may contain duplicates.
402
403<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3ANAMED-READTABLE-DESIGNATOR-20-28TYPE-29-29'></a>
404
405- [type] **NAMED-READTABLE-DESIGNATOR**
406
407    Either a symbol or a readtable itself.
408
409<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3AREADER-MACRO-CONFLICT-20CONDITION-29'></a>
410
411- [condition] **READER-MACRO-CONFLICT** *READTABLE-ERROR*
412
413    Continuable.
414   
415    This condition is signaled during the merge process if a reader
416    macro (be it a macro character or the sub character of a dispatch
417    macro character) is present in the both source and the target
418    readtable and the two respective reader macro functions differ.
419
420<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3AREADTABLE-DOES-ALREADY-EXIST-20CONDITION-29'></a>
421
422- [condition] **READTABLE-DOES-ALREADY-EXIST** *READTABLE-ERROR*
423
424    Continuable.
425
426<a name='x-28EDITOR-HINTS-2ENAMED-READTABLES-3AREADTABLE-DOES-NOT-EXIST-20CONDITION-29'></a>
427
428- [condition] **READTABLE-DOES-NOT-EXIST** *READTABLE-ERROR*
429
430  [059d]: #x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-ACKNOWLEDGEMENTS-20MGL-PAX-3ASECTION-29 "(EDITOR-HINTS.NAMED-READTABLES:@NAMED-READTABLES-ACKNOWLEDGEMENTS MGL-PAX:SECTION)"
431  [0bc2]: #x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-OVERVIEW-20MGL-PAX-3ASECTION-29 "(EDITOR-HINTS.NAMED-READTABLES:@NAMED-READTABLES-OVERVIEW MGL-PAX:SECTION)"
432  [373d]: #x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-REFERENCE-20MGL-PAX-3ASECTION-29 "(EDITOR-HINTS.NAMED-READTABLES:@NAMED-READTABLES-REFERENCE MGL-PAX:SECTION)"
433  [437a]: #x-28EDITOR-HINTS-2ENAMED-READTABLES-3AREADTABLE-DOES-NOT-EXIST-20CONDITION-29 "(EDITOR-HINTS.NAMED-READTABLES:READTABLE-DOES-NOT-EXIST CONDITION)"
434  [4b51]: #x-28EDITOR-HINTS-2ENAMED-READTABLES-3AREADTABLE-DOES-ALREADY-EXIST-20CONDITION-29 "(EDITOR-HINTS.NAMED-READTABLES:READTABLE-DOES-ALREADY-EXIST CONDITION)"
435  [58c6]: #x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-PREREGISTERED-20MGL-PAX-3ASECTION-29 "(EDITOR-HINTS.NAMED-READTABLES:@NAMED-READTABLES-PREREGISTERED MGL-PAX:SECTION)"
436  [62b8]: #x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-API-IDIOSYNCRASIES-20MGL-PAX-3ASECTION-29 "(EDITOR-HINTS.NAMED-READTABLES:@NAMED-READTABLES-API-IDIOSYNCRASIES MGL-PAX:SECTION)"
437  [6faf]: #x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-INTRODUCTION-20MGL-PAX-3ASECTION-29 "(EDITOR-HINTS.NAMED-READTABLES:@NAMED-READTABLES-INTRODUCTION MGL-PAX:SECTION)"
438  [77fa]: #x-28EDITOR-HINTS-2ENAMED-READTABLES-3AMERGE-READTABLES-INTO-20FUNCTION-29 "(EDITOR-HINTS.NAMED-READTABLES:MERGE-READTABLES-INTO FUNCTION)"
439  [8688]: #x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-LINKS-20MGL-PAX-3ASECTION-29 "(EDITOR-HINTS.NAMED-READTABLES:@NAMED-READTABLES-LINKS MGL-PAX:SECTION)"
440  [8b94]: #x-28EDITOR-HINTS-2ENAMED-READTABLES-3ADEFREADTABLE-20-28MGL-PAX-3AMACRO-29-29 "(EDITOR-HINTS.NAMED-READTABLES:DEFREADTABLE (MGL-PAX:MACRO))"
441  [958e]: #x-28EDITOR-HINTS-2ENAMED-READTABLES-3AMAKE-READTABLE-20FUNCTION-29 "(EDITOR-HINTS.NAMED-READTABLES:MAKE-READTABLE FUNCTION)"
442  [9b5b]: #x-28-22named-readtables-22-20ASDF-2FSYSTEM-3ASYSTEM-29 "(\"named-readtables\" ASDF/SYSTEM:SYSTEM)"
443  [acb7]: #x-28EDITOR-HINTS-2ENAMED-READTABLES-3AREADER-MACRO-CONFLICT-20CONDITION-29 "(EDITOR-HINTS.NAMED-READTABLES:READER-MACRO-CONFLICT CONDITION)"
444  [cf94]: #x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-EXAMPLES-20MGL-PAX-3ASECTION-29 "(EDITOR-HINTS.NAMED-READTABLES:@NAMED-READTABLES-EXAMPLES MGL-PAX:SECTION)"
445  [de3b]: #x-28EDITOR-HINTS-2ENAMED-READTABLES-3AIN-READTABLE-20-28MGL-PAX-3AMACRO-29-29 "(EDITOR-HINTS.NAMED-READTABLES:IN-READTABLE (MGL-PAX:MACRO))"
446  [e4cd]: #x-28EDITOR-HINTS-2ENAMED-READTABLES-3A-40NAMED-READTABLES-API-NOTES-20MGL-PAX-3ASECTION-29 "(EDITOR-HINTS.NAMED-READTABLES:@NAMED-READTABLES-API-NOTES MGL-PAX:SECTION)"
447  [fa0c]: #x-28EDITOR-HINTS-2ENAMED-READTABLES-3ANAMED-READTABLE-DESIGNATOR-20-28TYPE-29-29 "(EDITOR-HINTS.NAMED-READTABLES:NAMED-READTABLE-DESIGNATOR (TYPE))"
448
449* * *
450###### \[generated by [MGL-PAX](https://github.com/melisgl/mgl-pax)\]
Note: See TracBrowser for help on using the repository browser.