Flex Based Outline Generator
This little project was suggested by my participation in the thread Bison YACC compiler generator question in the Programming forum which was started by LQ member schmitta. It is a simple program which produces formatted outlines, or other indented text output, from plain text source files with a few simple markup options.
The original question in the linked thread related to a Flex/Bison generated parser, but as the thread progressed it seemed to me that some basic level of function could be provided relatively easily using only a Flex based scanner, or lexer, without the need for a grammar and generated parser. After rolling that idea around for a few days I decided to try to put it into code, and this is the result.
To be fair, the level of operation intended by schmitta may have been somewhat different than provided by the following application, but there was no clear specification provided. Based on the description in the thread, a subset of the control commands given there as examples and my own imagination of how those might work, I tried to write a simplest implementation using fewest lexer rules and a simple set of C functions.
The Flex source file may be found here, which includes build instructions, and an example input text with markup may be found here. Running the application with that example should produce the following output:
The original question in the linked thread related to a Flex/Bison generated parser, but as the thread progressed it seemed to me that some basic level of function could be provided relatively easily using only a Flex based scanner, or lexer, without the need for a grammar and generated parser. After rolling that idea around for a few days I decided to try to put it into code, and this is the result.
To be fair, the level of operation intended by schmitta may have been somewhat different than provided by the following application, but there was no clear specification provided. Based on the description in the thread, a subset of the control commands given there as examples and my own imagination of how those might work, I tried to write a simplest implementation using fewest lexer rules and a simple set of C functions.
The Flex source file may be found here, which includes build instructions, and an example input text with markup may be found here. Running the application with that example should produce the following output:
Code:
Outline Generator Outline Following is a brief outline of the major features and basic operation of an outline generator application constructed within a Flex lexer specification. This outline has been generated using the application described. 1) Basic operational features a) Generates formatted output as indented outlines from plain text source with simple markup b) Automatically orders indented outline prefixes c) Provides top, bottom, left, right page margins d) Prints centered page number on last line of page e) Supports shell style comments (^#...$) f) Supports Flex debug trace at runtime (-d opt) 2) Source markup rules, apply to all following lines a) Page size and margins (one per line) 1) .pl [0-9]+ - Set page length lines 2) .pw [0-9]+ - Set page width chars 3) .tm [0-9]+ - Set top margin lines 4) .bm [0-9]+ - Set bottom margin lines 5) .lm [0-9]+ - Set left margin spaces 6) .rm [0-9]+ - Set right margin spaces 7) .is [0-9]+ - Set indent spaces per level b) Control specifiers (one per line) 1) .si - Shift in one level 2) .so - Shift out one level 3) .sl - Shift out to left margin 4) .it - Toggle ordering prefixes off/on (def on) (Prints lines or paragraphs wrapped to current indentation level when toggled off) c) Title lines (Single lines, no wrap) 1) .tl[TEXT] - Print text aligned to left margin 2) .tc[TEXT] - Print text aligned to page center 3) .tl/.tc - Without trailing text prints empty line 3) Examples of use (program name is ol) a) ./ol infile b) ./ol -d infile (enable debug trace) c) ./ol < infile > outfile d) ./ol -h (Show help and exit) <... SNIP ...> Page 1
Total Comments 0