LISP Styler

Function Syntax (LM:LISPStyler <file> <styles> <extn> <<>>)
Current Version 1.0
Download LISPStyler.lsp
View HTML Version LISPStyler.html
Arguments
Symbol Type Description
file String Filename of LISP to which style tags are to be added
styles List List of style tags to use for various code items (described below)
extn String Extension of resultant output file (e.g. ".html")
<> Boolean Flag to determine whether '<' and '>' are replaced with '&lt;' and '&gt;'
Returns
The return of this function is undefined

Program Description

This program is a generic styling engine, enabling a user to add specified styling tags to bring colour and/or formatting to various code elements of a LISP file.

Upon calling the subfunction with the required arguments (detailed below), the LISP file supplied will be processed and an output with the same name will be saved under the same directory using the extension specified.

Notes on Function Parameters

File

A full filename of a LISP file to process - the filename may use forward slashes ( / ) or double-backslashes ( \\ ).

Styles

A list of style tags to enclose various code items. Each element in the list is a list of two items: the first is the opening style tag for a code item, the second is the closing tag.

This list must be in the following form:

(                                                             
  (<container open>   <container close>)   ;; e.g. (<pre> </pre>)
  (<quote     open>   <quote     close>)   ;; quotes/dots
  (<bracket   open>   <bracket   close>)   ;; parentheses
  (<mcomment  open>   <mcomment  close>)   ;; multiline comments
  (<scomment  open>   <scomment  close>)   ;; single comments
  (<string    open>   <string    close>)   ;; strings
  (<protected open>   <protected close>)   ;; protected symbols
  (<integer   open>   <integer   close>)   ;; integers
  (<real      open>   <real      close>)   ;; reals
)

If no style tag is required for a specific code item, the entry must still be present as a list of two empty strings. For more examples of this argument, see the examples of the usage of this program, below.

Extn

The file extension for the output file (with dot included, e.g. ".txt").

This extension must not be ".lsp", else the input file will be overwritten by the output from this subfunction.

<>

This argument is a boolean flag to determine whether the characters < and > are to be replaced by &lt; and &gt; in the output file; if T, such characters will be replaced.

This argument is necessary when formatting code for such languages as HTML, where such characters, if not replaced, are interpreted as the inherent markup language.

Examples of Usage

Here I illustrate the function usage on some sample code, displaying three styles of code formatting and furthermore demonstrating the styles argument used to create the code appearance. Of course, these are only three of the endless possibilities available to the user.

The examples shown here demonstrate the use of BBCode to add colour to various code items, however, as shown by my last example, formatting tags used in other languages may also be added.

Example calling functions are also included in the program file.

Example Style 1

This style aims to emulate the standard colours used by the Visual LISP Editor (VLIDE).

Style1.png

;; 'styles' argument for Style 1

'(
   ("[code]"            "[/code]" )  ;; Container
   ("[color=DARKRED]"   "[/color]")  ;; Quotes/Dots
   ("[color=RED]"       "[/color]")  ;; Brackets
   ("[color=#990099]"   "[/color]")  ;; Multiline Comments
   ("[color=#990099]"   "[/color]")  ;; Single Comments
   ("[color=#a52a2a]"   "[/color]")  ;; Strings
   ("[color=BLUE]"      "[/color]")  ;; Protected Symbols
   ("[color=#009900]"   "[/color]")  ;; Integers
   ("[color=#009999]"   "[/color]")  ;; Reals
 )

Example Style 2

This style doesn't add colour to parentheses, integers or reals - notice how these items appear as empty strings in the styles argument.

Style2.png

;; 'styles' argument for Style 2

'(
   ("[code]"            "[/code]" )  ;; Container
   ("[color=DARKRED]"   "[/color]")  ;; Quotes/Dots
   (""                  ""        )  ;; Brackets
   ("[color=NAVY]"      "[/color]")  ;; Multiline Comments
   ("[color=BLUE]"      "[/color]")  ;; Single Comments
   ("[color=RED]"       "[/color]")  ;; Strings
   ("[color=GREEN]"     "[/color]")  ;; Protected Symbols
   (""                  ""        )  ;; Integers
   (""                  ""        )  ;; Reals
 )

Example Style 3

Finally, this style only adds colour to comments and protected symbols - a more minimalist approach.

Style3.png

;; 'styles' argument for Style 3

'(
   ("[code]"            "[/code]" )  ;; Container
   (""                  ""        )  ;; Quotes/Dots
   (""                  ""        )  ;; Brackets
   ("[color=GREEN]"     "[/color]")  ;; Multiline Comments
   ("[color=GREEN]"     "[/color]")  ;; Single Comments
   (""                  ""        )  ;; Strings
   ("[color=BLUE]"      "[/color]")  ;; Protected Symbols
   (""                  ""        )  ;; Integers
   (""                  ""        )  ;; Reals
 )

Example of HTML Styling

Note that HTML style tags may also be used for code that is to be displayed on websites, for example.

The following styles argument would add the necessary formatting used to display code on my website.

;; 'styles' argument for www.lee-mac.com

'(
   ("<pre>"                 "</pre>" )  ;; Container
   ("<span class=\"quot\">" "</span>")  ;; Quotes/Dots
   ("<span class=\"brkt\">" "</span>")  ;; Brackets
   ("<span class=\"cmt\">"  "</span>")  ;; Multiline Comments
   ("<span class=\"cmt\">"  "</span>")  ;; Single Comments
   ("<span class=\"str\">"  "</span>")  ;; Strings
   ("<span class=\"func\">" "</span>")  ;; Protected Symbols
   ("<span class=\"int\">"  "</span>")  ;; Integers
   ("<span class=\"rea\">"  "</span>")  ;; Reals
 )

textsize

increase · reset · decrease

Designed & Created by Lee Mac © 2010