noweb

From Wikipedia, the free encyclopedia

noweb is a free literate programming tool, created in 1989-1999 by Norman Ramsey [1], and designed to be simple, easily extensible and language independent.

Like in WEB and CWEB main components of noweb are two programs: "notangle", which extracts 'machine' source code from the source texts, and "noweave", which produces nicely-formatted printable documentation.

noweb 'out of the box' supports TeX, LaTeX, HTML, and troff back ends and works with any programming language. Besides simplicity this is the main advantage over WEB, which needs different versions, to support programming languages other than Pascal. (thus CWEB emerged, to support C and similar languages)

[edit] Noweb's input

A noweb input text contains program source code interleaved with documentation. It consists of so-called chunks that are either code-chunks or documentation-chunks.

It uses LaTeX code for documentation chunks, but you may easily use any form you like.

Code chunks aren't treated specially by noweb's tools - they may be placed in any order and when needed, they are just concatenated, chunk-references in code are dereferenced and the whole requested source code is extracted.

[edit] Example of a simple noweb program

This is an example of a hello-world program(s) with documentation:


@
\section{Hello world}

Today I awakened and decided to write
some code, so I started to write a Hello World in \textsf C.

<<hello.c>>=
/*
  <<license>>
*/
#include <stdio.h>

int main(int argc, char *argv[]) {
  printf("Hello World!\n");
  return 0;
}
@
\noindent \ldots then I did the same in PHP.

<<hello.php>>=
<?php
  /*
  <<license>>
  */
  echo "Hello world!\n";
?>
@
\section{License}
Later, same day some lawyer reminded me about licenses.
So, here it is:

<<license>>=
This work is placed in the public domain.
@

Assuming that the above code is placed in a file named 'hello.noweb', the command to extract the human-readable document in HTML format is:

noweave -filter l2h -index -html hello.noweb | htmltoc > hello.html

... and in LaTeX format:

noweave -index -latex hello.noweb > hello.tex

To extract machine source code:

notangle -Rhello.c hello.noweb > hello.c

notangle -Rhello.php hello.noweb > hello.php

[edit] External links

Languages