• Stars
    star
    110
  • Rank 316,770 (Top 7 %)
  • Language
    Common Lisp
  • License
    BSD 2-Clause "Sim...
  • Created almost 7 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A portable Common Lisp reader that is highly customizable, can recover from errors and can return concrete syntax trees

Eclector: A portable and extensible Common Lisp Reader

Introduction

The eclector system provides a portable implementation of a reader following the Common Lisp specification.

eclector is under active development. Its ASDF system structure, package structure, exported symbols and protocols may change at any time but are becoming less and less likely to do so in incompatible ways. Consult the NEWS file or the "Changelog" section of the manual for lists of changes in specific versions.

This document only gives a very brief overview and highlights some features. Proper documentation can be found in the documentation directory.

Usage Overview and Highlights

Basics

In the simplest case, the eclector reader can be used like any Common Lisp reader:

  • (with-input-from-string (stream "(1 2 3)")
      (eclector.reader:read stream))
    ; => (1 2 3)
  • (eclector.reader:read-from-string "#C(1 1)")
    ; => #C(1 1) 7

Error Recovery

In contrast to many other reader implementations, eclector can recover from most errors in the input supplied to it and continue reading. This capability is realized as a restart named eclector.reader:recover which is established whenever an error is signaled for which a recovery strategy is available.

For example, the following code

(handler-bind ((error (lambda (condition)
                        (let ((restart (find-restart 'eclector.reader:recover)))
                          (format t "Recovering from error:~%~2@T~A~%using~%~2@T~A~%"
                                  condition restart))
                        (eclector.reader:recover))))
  (eclector.reader:read-from-string "`(::foo ,"))

produces this:

Recovering from error:
  A symbol token must not start with two package markers as in ::name.
using
  Treat the character as if it had been escaped.
Recovering from error:
  While reading unquote, expected an object when input ended.
using
  Use NIL in place of the missing object.
Recovering from error:
  While reading list, expected the character ) when input ended.
using
  Return a list of the already read elements.
; => (ECLECTOR.READER:QUASIQUOTE (:FOO (ECLECTOR.READER:UNQUOTE NIL))) 9

indicating that eclector recovered from multiple errors and consumed all input. Of course, the returned expression is likely unsuitable for evaluation, but recovery is useful for detecting multiple errors in one go and performing further processing such as static analysis.

Custom Parse Results

Using features provided in the eclector.parse-result package, the reader can produce parse results controlled by the client, optionally including source tracking and representation of skipped input (due to e.g. comments and reader conditionals):

(defclass my-client (eclector.parse-result:parse-result-client)
  ())

(defmethod eclector.parse-result:make-expression-result
    ((client my-client) (result t) (children t) (source t))
  (list :result result :source source :children children))

(defmethod eclector.parse-result:make-skipped-input-result
    ((client my-client) (stream t) (reason t) (source t))
  (list :reason reason :source source))

(with-input-from-string (stream "(1 #|comment|# \"string\")")
  (eclector.parse-result:read (make-instance 'my-client) stream))

Concrete Syntax Trees

The eclector.concrete-syntax-tree system provides a variant of the eclector reader that produces instances of the concrete syntax tree classes provided by the concrete syntax tree library:

(eclector.concrete-syntax-tree:read-from-string "(1 2 3)")
; => #<CONCRETE-SYNTAX-TREE:CONS-CST raw: (1 2 3) {100BF94EF3}> 7 NIL

More Repositories

1

Concrete-Syntax-Tree

Concrete Syntax Trees represent s-expressions with source information
Common Lisp
60
star
2

Cleavir

an implementation-independent framework for creating Common Lisp compilers
Common Lisp
46
star
3

wscl

Sources of the "Well Specified Common Lisp" specification which is based on the final draft of the Common Lisp standard but is not a new Common Lisp standard.
TeX
38
star
4

Trucler

Environment protocol for Common Lisp compilers.
Common Lisp
33
star
5

ctype

CL type system implementation
Common Lisp
26
star
6

dpans

Sources - with fixes - of the draft Common Lisp specification proposed to the American National Standard for Information Systems as well as the accompanying X3J13 cleanup issues
TeX
12
star
7

Clostrum

First Class Global Environments
Common Lisp
12
star
8

Inravina

A portable and extensible Common Lisp pretty printer.
Common Lisp
11
star
9

Maclina

Common Lisp bytecode compiler
Common Lisp
10
star
10

Ecclesia

Utilities for parsing Lisp code - previously known as cleavir-code-utilities
Common Lisp
9
star
11

Cyclosis

An implementation of Common Lisp streams
Common Lisp
8
star
12

Incless

A portable and extensible Common Lisp printer implementation
Common Lisp
7
star
13

Khazern

A portable and extensible Common Lisp LOOP implementation
Common Lisp
6
star
14

editing-requirements

Collecting requirements for editing, parsing, analyzing and presenting Common Lisp code
5
star
15

Invistra

A portable and extensible Common Lisp FORMAT implementation
Common Lisp
5
star
16

Incrementalist

Incremental parsing of Common Lisp code in a Cluffer editor buffer
Common Lisp
4
star
17

Parcl

Common Lisp
4
star
18

Quaviver

A portable and extensible floating point base conversion and string library
Common Lisp
4
star
19

Constrictor

A library that implements the functionality of the Conses dictionary of the Common Lisp standard
Common Lisp
3
star
20

Anatomicl

Portable implementation of Common Lisp Structures
Common Lisp
3
star
21

Consecution

An implementation of the Common Lisp sequence functions.
Common Lisp
3
star
22

Buoy

Embryonic floating-point library for Common Lisp
Common Lisp
3
star
23

Extrinsicl

Extrinsic Common Lisp environment
Common Lisp
2
star
24

Tazivor

A portable Common Lisp inspector
Common Lisp
1
star
25

wscl-ct

Common Lisp
1
star