【问题标题】:Choose extension of :file component in asdf defsystem在 asdf defsystem 中选择 :file 组件的扩展名
【发布时间】:2023-04-03 09:10:01
【问题描述】:

我 90% 确定答案在 this paragraph of the asdf documentation 中,但我似乎无法理解。 我想知道我是否能够将不以“.lisp”结尾的源文件作为文件组件。例如,通常我有类似的东西

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

如您所见 :file 组件没有指定扩展名。我想知道是否可以加载不以“.lisp”结尾的 lisp 文件。

我想要这个的原因有点奇怪,但对问题没有影响,所以请随意跳过下一点。

我有一些文件“test.mylang”,它以以下内容开头

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

#!mylang 是一个阅读器宏,它让我的#'mylang 函数控制解析文件的其余部分。因此,如果我有一个 python 解析器,我会使用 #!python 并且我的 #'python 函数将负责解析。 在这些情况下,我希望使用 .mylang.py 扩展名,以便编辑人员立即知道如何突出显示代码,即使它无论如何都会被加载为 lisp。

谢谢大家

【问题讨论】:

  • 我认为通过使用#p"foo.py",它可能会起作用(如(:file #p"foo.py")
  • 怕不是Error while trying to load definition for system hash-bang-lang .. There is no applicable method for the generic function .. FIND-COMPONENT .. when called with (#<ASDF:SYSTEM "hash-bang-lang"> #P"test.py")

标签: common-lisp reader-macro


【解决方案1】:

:file 组件类型将文件扩展名强制为.lisp。如果你需要一些其他的扩展,你需要一个新的组件类型。

(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")))

【讨论】:

  • 谢谢,这将给我一个借口来研究 asdf 扩展机制,它已经在我的待办事项列表上一段时间了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-13
  • 1970-01-01
  • 1970-01-01
  • 2017-12-24
  • 1970-01-01
  • 2012-11-14
  • 1970-01-01
相关资源
最近更新 更多