You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: DESIGN.md
+22-10Lines changed: 22 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# parseclj Design Goals / Roadmap
2
2
3
-
parseclj is an Emacs Lisp library for parsing Clojure code and EDN data. It
4
-
supports several input and output formats, all powered by the same shift-reduce
5
-
parser function.
3
+
parseclj is an Emacs Lisp library for parsing Clojure code and [EDN
4
+
data](https://github.com/edn-format/edn). It supports several input and output
5
+
formats, all powered by the same shift-reduce parser function.
6
6
7
7
This documents describes the design goals for parseclj, and as such may describe features which are not implemented yet.
8
8
@@ -39,7 +39,7 @@ On the other hand Emacs supports strings/buffers with arbitrary encoding, on the
39
39
40
40
## Architecture
41
41
42
-
The implementation is implemented in three parts: a lexer, a parser, and multiple reducers.
42
+
The implementation is implemented in three parts: a lexer, a parser, and [multiple reducers](#multiple-reducers).
43
43
44
44
### Lexer
45
45
@@ -214,7 +214,17 @@ Unmatched closing delimiter:
214
214
215
215
In many cases it will be desirable to "fail fast", and raise an error as soon as a syntax error is encountered. A `reduce-branch` function can do so if it wishes by checking its input sequence for raw tokens, and raising an error if any are present.
216
216
217
-
## EDN vs Clojure
217
+
## Multiple Reducers
218
+
219
+
While the shift-reduce parser parses input, it reduces parsed values (leafs tokens and collections) using "reducing functions". These functions are in charge of giving actual meaning to the parsed data.
220
+
221
+
Currently, there are two sets of reducing functions implemented: one set that reduces parsed values to AST data structures, and another one that reduces to Emacs Lisp values.
222
+
223
+
The AST reducing functions are part of [`parseclj`](https://github.com/clojure-emacs/parseclj), while the Emacs Lisp reducing functions are separated into a differente package called [`parseedn`](https://github.com/clojure-emacs/parseedn).
224
+
225
+
To understand why these two set of reducing functions are separated, it's important to look at the difference between EDN and Clojure, and also between Emacs Lisp elements and EDN elements.
226
+
227
+
### EDN vs Clojure
218
228
219
229
EDN syntax is a subset of Clojure syntax used for representing data (as opposed to code).
220
230
@@ -223,7 +233,7 @@ Several constructs that are common in Clojure code are not valid in EDN. This in
223
233
- quoting, syntax quoting, syntax quote splicing, etc.
224
234
- read time evaluation with `#=(,,,)`
225
235
226
-
## Dealing with tagged literals
236
+
### Dealing with tagged literals
227
237
228
238
EDN/Clojure syntax is extensible. Values can be prefixed with user-provided tags, which indicates they need to be transformed after reading by a registered handler function.
229
239
@@ -233,7 +243,7 @@ The EDN parser functions will take an optional tag handler function. This functi
233
243
234
244
When parsing code to an AST the situation is different, here tags simply become part of the AST, without caring about their semantics.
235
245
236
-
## Representing EDN as Emacs Lisp values
246
+
### Representing EDN as Emacs Lisp values
237
247
238
248
See also the section at the top regarding differences between Clojure's data types vs those available in Emacs Lisp.
239
249
@@ -246,11 +256,11 @@ These are the choices that the edn.el library has made:
246
256
- represent characters as integers, *but* parse `\newline` `\return` `\space` and `\tab` as the symbols `'newline` `'return` etc.
247
257
- parse `true` as `t`, `nil` and `false` as `nil`.
248
258
249
-
### Differences with EDN.el
259
+
#### Differences with EDN.el
250
260
251
261
At the moment the `parseedn-*` copy the parsing behavior of edn.el, *except* that the character literals `\newline`, `\return`, `\space`, and `\tab` are parsed to their character code (10, 13, 32, and 9 respectively), instead of to symbols.
252
262
253
-
## AST
263
+
### AST
254
264
255
265
An AST (abstract syntax tree) is a tree structure made up of nodes. A node looks like this
256
266
@@ -274,6 +284,8 @@ Non-leaf nodes contain a list of `:children`.
274
284
275
285
## Public API
276
286
287
+
> Disclaimer: outdated information -- this API has been deprecated in favor of [Alternative Package Layout](#alternative-package-layout), and it's only kept here for historical purposes.
288
+
277
289
parseclj provides three "parse modes"
278
290
279
291
- `edn` meant for parsing data, it parses EDN to emacs lisp data
@@ -432,7 +444,7 @@ corresponding type in Emacs. `nil' and `false' form a
432
444
particularly poignant case, both are converted to `nil'.")
0 commit comments