|
This chapter presents fontification functions, that is functions that can be used in prgm environment to colorize computer program texts. For the sake of the example, all along this chapter we will a function for fontifiying Shell scripts. We will call this function shell. This fontification scheme will be very simple. Prompts, that is string of characters start at the beginning of a line and ending with a ">" character will be rendered in a bold font. Shell comments, that is strings of characters starting with a "#" ending with the end of line are displayed using an italic face. Shell results, that is lines not starting by a prompt, are displayed in red. For instance:
A fontification function is a function accepting one parameter. This formal parameter is bound to a string representing the text to be fontified. It is to the responsibility of the fontification function to process any computation on this string. The result of the fontification will be included in the target file. That is, the fontification function takes a string and returns a Scribe expression representing the fontified program. The definition of the shell fontification is:
In order to implement the fontification we are using Bigloo regular parser. This mechanism enables a lexical analysis of string of characters. (See Bigloo for a documentation on lexical analysis in Scheme.)
|