common-lispreader-macro

Choose extension of :file component in asdf defsystem


I am 90% sure the answer is in this paragraph of the asdf documentation , but I seem unable to grok it. I am wondering if I am able to have source files that do not end in ".lisp" as file components. For example, usually I have something like

(asdf:defsystem #:hash-bang-lang
  :serial t
  :depends-on (#:named-readtables)
  :components ((:file "package")
               (:file "hash-bang-lang")))

As you can see the :file components do not specify the extension. I am wondering if I can load lisp files that do not end in ".lisp".

The reason I want this is a little odd but has no impact on the question so feel free to skip the next bit.

I have some file "test.mylang" and it starts with the following

(in-package :hash-bang-lang)
(in-readtable hash-bang)
#!mylang
..rest of file..

The #!mylang is a reader macro that gives my #'mylang function control of parsing the rest of the file. So if I had a parser for python I would use #!python and my #'python function will take up the parsing. In those cases I would like to have the .mylang or .py extension so editors know instantly how to highlight the code, even though it's going to be loaded as lisp anyway.

Thanks folks


Solution

  • The :file component type forces the file extension to .lisp. If you need some other extension, you need a new component type.

    (defpackage #:mylang-system
      (:use #:cl #:asdf))
    (in-package #:mylang-system)
    
    (defclass mylang-file (cl-source-file)
      ((type :initform "mylang")))
    
    (defsystem test-ext
      :encoding :utf-8
      :components ((:file "package")
                   (:mylang-file "hash-bang-lang")))