In last month's column, if you had the following points, you would understand that the availability of the underlying code would not be a problem:
How to identify configuration scripts
How to choose which configuration to allow
Identify which environment requires black box scalability
Measuring the build complexity of scalability
When you provide this extensibility to the configuration script, you are actually building a language.
You also recognize that using s-expression is an effective way to quickly build a configuration language, given the black box scalability of your application. We'll delve into the s-expression in this article and provide an example of how these s-expression can be used to quickly and easily establish a configuration language for a particular application.
Some knowledge about S-expression
Let's recall that s-expression is a syntactic representation of the list of elements separated by parentheses. There are three forms of s-expression:
Empty element list
Non-empty element list
A single atomic element (such as a word)
S-expression is useful as a configuration language because they are easy to parse. The general S-expression parser reads the data into the program, and then the program checks to see if the expression adheres to more specific syntax constraints. In this way, we get all the benefits of parsing input-such as early error-input detection and increased security--eliminating the energy costs and overhead of writing and maintaining a regular parser. Similarly, the output of an error message can be precise and helpful when tracing the source of a syntax error, unlike the parser builder constructs.
"S" is more advantageous than XML
As I mentioned in the previous article, many of the benefits of using s-expression can also be obtained by using an xml-based configuration language. The main advantage over XML based on the S-expression configuration language is that it is very lightweight and fast-built.
Similarly, in many cases, s-expression configuration scripts are easier to read and edit than equivalent xml-based scripts. When we discuss some of the following examples based on s-expression scripts, consider what they look like in XML notation.
Example: adding macro support to the editor
Suppose we want to add simple macro support to a text editor, allowing users to define complex sequences of basic operations. We may even want to add support for loops or recursive constructs.
Here is an example of a possible scenario for a macro:
Listing 1. A simple macro
(define (cutAndPasteAtEnd)
(sequence
(cut HIGHLIGHTED_TEXT)
(move-to END_OF_DOCUMENT)
(paste CLIPBOARD))