6.16. Tanglers

A tangler is a driver that accepts lines of code in a particular language or class of languages, writes it to a code file, possibly pretty printing it, and displays it in a weaver fixed at construction time.

Tanglers may also build tables of information about the code.

The main method of a tangler is writeline, which requires three arguments: the line of code to be tangled, and the name of the original file from which the line came, and the line number within the original file from which the line came.

If the target language supports original source references (like c's #line directive), the tangler should also insert a directive into the code file using the supplied arguments, unless the file name is the same as the previous line's original source file, or the line number is not one more than the previous line's original line number.

The tangler should attach the original filename and line number to it's sink device, since more than one tangler may write to the same sink.

A tangler may supply a write_comment method accepting a single argument, some text to be comments. The tangler may assume the text does not contain any end of line characters. It may write the text into the code file as comments, not necessarily on one line; however, it may not write anything which affects the semantics of the program being generated. The comment should be woven as ordinary program text.

A tangler may supply a method get_comment_tangler. If it does, then, when called with no arguments, it shall return a tangler which can be used to write a single block of comments to the same sink and weaver as itself.

A tangler may supply a method get_string_tangler. If it does, it shall accept two or more arguments, the first being an end of line string, and the second a width. A string tangler so returned shall produce a string in the target language, whose text in the target language shall have the same natural language interpretation as the text fed to the string tangler via calls to its writeline method.

The string tangler may strip trailing, leading, or interior whitespace from the data supplied via the writeline method, and it may insert the supplied end of line string in appropriate places. It may also translate the encoding of the input to another encoding, or translate the natural language input to another natural language.

The string tangler may not insert end of line markers other than the supplied marker. (The target operating system for execution of the code is not known to the string tangler. Also, the caller may supply a blank, to inhibit multi-line output, or may supply a null string, to force concatenation of non-blank text.

The width parameter is a hint to the string tangler indicating approximately how long lines should be if the string tangler is flowing, justifying, or otherwise formatting the text as lines of a paragraph.

Note: the purpose of string tanglers is simply to allow the programmer to write natural language text in Interscript source files without having to worry about escape characters, quoting, encodings, or line endings. Text so provided may be intended to be output for user help, as a message, or, as part of a run-time documentation system.

Although Python currently supports only strings of 8 bit characters, a Japanese programmer might construct a c string tangler that translated some multi-byte encoding of Japanese characters into a c 'wide' string literal with a 16 bit encoding.

Start python section to interscript/tanglers/__init__.py[1 /1 ]
     1: #line 84 "tanglers.ipk"
     2: # tanglers
     3: 
End python section to interscript/tanglers/__init__.py[1]


6.16.1. Tangler Base class
6.16.2. Null Tangler
6.16.3. Document Tangler
6.16.4. Data Tangler
6.16.5. c Tangler
6.16.6. c++ Tangler
6.16.7. Java Tangler
6.16.8. ocaml Tangler
6.16.9. Tcl Tangler
6.16.10. Python Tangler
6.16.11. Python Tangler
6.16.12. Python comment tangler
6.16.13. Perl Tangler
6.16.14. Suggested replacement Code