Skip to content

Latest commit

 

History

History
125 lines (92 loc) · 2.92 KB

0038-asdf-linguist.org

File metadata and controls

125 lines (92 loc) · 2.92 KB

asdf-linguist

This is a set of extensions for ASDF to compile or preprocess various languages with a single tool.

To demonstrate, how it works, I’ve created a small example with a system which contains only one Sass stylesheet. Sass is a language which compiles into CSS and provides interesting features such as mixins, variables and others.

To make this example work, you’ll need to install Sass compiler.

On OSX it is as simple, as doing:

brew install node-sass

Next, we need to create an ASDF system definition:

(defsystem "foo"
  :defsystem-depends-on (:asdf-linguist)
  :components ((:sass "stylesheet")))

Here we are using special component type “:sass” which is predefined by “asdf-linguist”. Also, we are telling ASDF to load this extension before building our system.

After that, we need to create a stylesheet. It will be hierarchical and without semicolons because this is Sass:

section {
    h1 {
        color: red
    }
    p {
        font-size: 2em
    }
}

Now we can load our system and we’ll see how it compiles our stylesheet into the plain CSS:

POFTHEDAY> (asdf:load-system :foo)
; sass stylesheet.scss stylesheet.css

Here is the result:

section h1 {
  color: red;
}
section p {
  font-size: 2em;
}

Let’s take a look at how “asdf-linguist defines a transformation which makes this magic happen!

It defines a new component type with this simple call:

(define-shell-component sass
  :input-type "scss"
  :output-type "css"
  :shell-command "sass")

Simple, isn’t it?

There is also another way to define components in case if you want to write it in Lisp.

Let’s pretend we’d like to use a Lass instead of Sass. Lass is a lispy equivalent of Sass, I wrote about it before.

To do this we’ll need to define such a component:

POFTHEDAY> (asdf-linguist::define-component lass
             :input-type "lass"
             :output-type "css"
             :compile-function (lambda (input-pathname output-pathname)
                      (lass:generate input-pathname
                                     :out output-pathname
                                     :pretty t)))

In this case, the result will be almost the same as with Sass:

section h1{
    color: red;
}

section p{
    font-size: 2em;
}

I think this is a very convenient way to add support for new filetypes into the ASDF. This project already supports many processors out of the box. Check them out in this test system.