check-bnf

2022-07-08

Macro arguments checker.

Upstream URL

github.com/hyotang666/check-bnf

Author

SATO Shinichi

License

MIT
README

CHECK-BNF 8.0.0

What is this?

Macro arguments checker.

Current lisp world

Common Lisp has a true macro. Writing macro means extending the compiler i.e. creating a new language.

Issues

Lack of documentation. Do you want to use LANGUAGE which has no documentation nor BNF?

Proposal

Check-bnf provides a bnf like syntax checker.

It allows you to write macro arguments definition.

It helps the third person to understand your macro.

Usage

* (defmacro mydefun (&whole whole name lambda-list &body body)
  (check-bnf (:whole whole)
    ((name (or symbol setf-name))
     (setf-name ((eql setf) symbol)))
    ((lambda-list list)))
  (list* name lambda-list body))

MYDEFUN
* (mydefun "name" () :dummy)

debugger invoked on a SYNTAX-ERROR in thread
#<THREAD "main thread" RUNNING {10016C0073}>:
  NAME : "name" comes.
  Last failed at SETF-NAME.
    Detail: SETF-NAME require CONS but "name".

    Definition

    NAME      := [ SYMBOL | SETF-NAME ]
    SETF-NAME := ((EQL SETF) SYMBOL)

For detail, see spec file.

DOC

You may emb bnf as documentation. Macro DOC allows you to do it by read time evaluation and read time labeling.

(defmacro your-macro (&whole w a)
  #.(check-bnf:doc "Header for your-macro"
      #0=(check-bnf:check-bnf (:whole w)
           ((a symbol))))
  #0#
  `',a)
=> YOUR-MACRO

(documentation 'your-macro 'function)
=> "Header for your-macro
A := SYMBOL
"

DEFBNF

Your macro may have similar syntax e.g. CASE, CCASE, and ECASE. In such cases, you can define global BNF by DEFBNF.

DEFBNF has almost the same syntax as CHECK-BNF but except accepts only one definition and alias is invalid.

Currently <LAMBDA-LIST>, <FUNCTION-TYPE> and <DECLARATION> is provided.

From developer

Product's goal

License

MIT

Developed with

SBCL

Tested with

  • SBCL/2.2.4
  • CCL/1.12.1
  • CLISP/2.49
  • CMUCL/21D
  • ECL/21.2.1
  • Allegro/10.1
  • ABCL/1.9.0

Known issue.

CCL

Due to its own issue, ccl signals warnings. But the check-bnf features are works fine. In the test, we just muffled it.

CLISP

CLISP say

The Lisp Pretty Printer implementation is not perfect yet.

CHECK-BNF works fine but the printed message is a little bit strange in clisp. For details see spec file.

ABCL

CHECK-BNF works fine but the printed message is a little bit strange in abcl due to the abcl pretty printing issue.

Currently tests about pretty printings are ignored.

Allegro

Allegro insert pprint logical block automatically for condition. Consequently, error message format becomes different from other implementations. Two tests about error message format are skipped.

(simple-condition-format-control (make-condition 'simple-condition :format-control ""))
=> "~1@<~:@>"

Installation

quicklisp supported.

* (ql:quickload :check-bnf)

Dependencies (5)

  • alexandria
  • closer-mop
  • jingoh
  • matrix-case
  • millet

Dependents (2)

  • GitHub
  • Quicklisp