• Stars
    star
    641
  • Rank 67,420 (Top 2 %)
  • Language
    D
  • License
    Other
  • Created almost 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A literate programming tool for any language

Literate

What is Literate programming?

Literate programming is a style of programming invented by Donald Knuth, where the main idea is that a program's source code is made primarily to be read and understood by other people, and secondarily to be executed by the computer.

This frees the programmer from the structure of a program imposed by the computer and means that the programmer can develop programs in the order of the flow of their thoughts.

A Literate program generally consists of explanation of the code in a natural language such as English, interspersed with snippets of code to be executed. This means that Literate programs are very easy to understand and share, as all the code is well explained.


Literate is a tool for creating literate programs.

The goal of this project is to create a literate programming tool which keeps most, if not all of the features of Knuth and Levy's original CWEB system, but simplifies the system and adds even more features.

You can view the main website about Literate here including a manual on how to use Literate.

Features

  • Supports any language including syntax highlighting and pretty printing in HTML
  • Markdown based -- very easy to read and write Literate source.
  • Reports syntax errors back from the compiler to the right line in the literate source
  • Generates readable and commented code in the target language (the generated code is usable by others)
  • Supports TeX equations with $ notation.
  • Literate source code is readable whether you are looking at the .lit file, or the generated HTML.
  • Highly customizable (you can add your own HTML or CSS)
  • Runs fast -- wc.lit compiled for me in 7ms for both code and HTML output
  • Automatically generates hyperlinks between code sections
  • Formatted output similar to CWEB
  • Supported by micro (by default)
  • Compatible with Vim (literate.vim)

Example

Here is a trivial example of a literate program saved in the file hello.lit.

For a full example of a literate program, please see examples/wc.lit which is a literate implementation of the wc (word count) program found on Unix systems. You can find the compiled html here.

@title Hello world in C

@s Introduction

This is an example hello world C program.
We can define codeblocks with `---`

--- hello.c
@{Includes}

int main() {
    @{Print a string}
    return 0;
}
---

Now we can define the `Includes` codeblock:

--- Includes
#include <stdio.h>
---

Finally, our program needs to print "hello world"

--- Print a string
printf("hello world\n");
---

To compile this code simply run

$ lit hello.lit

Which generates hello.c and hello.html.

You can also find this program in examples/hello.lit.

Installation

Prebuilt binaries

Download
Mac OS X
64 bit Linux
32 bit Linux
Arm Linux

Building from Source

Mac

On Mac you can use brew to build Literate from source:

$ brew tap zyedidia/literate
$ brew install --HEAD literate

For now, Literate is head only.


Literate is made with the D programming language so you must install dmd (D compiler) and dub (D package manager). Then you should download the zip or clone the repository and run the following commands:

$ cd Literate
$ make

You can find the binary in path/to/Literate/bin (you may want to add this to your path or move it to /usr/local/bin).

Editors

Micro

The micro editor has support for literate by default. Download it here.

Vim

You might also want to go install the Vim plugin (it has syntax highlighting of the embedded code, linting with Neomake, and jumping to codeblock definitions). I'm sorry that no other editors are supported -- I don't know how to make plugins for other editors.

Usage

Lit: Literate Programming System

Usage: lit [options] <inputs>

Options:
--help       -h         Show this help text
--tangle     -t         Only compile code files
--weave      -w         Only compile HTML files
--no-output  -no        Do not generate any output files
--out-dir    -odir DIR  Put the generated files in DIR
--compiler   -c         Report compiler errors (needs @compiler to be defined)
--linenums   -l    STR  Write line numbers prepended with STR to the output file
--md-compiler COMPILER  Use COMPILER as the markdown compiler instead of the built-in one
--version    -v         Show the version number and compiler information

For more information see the manual.

Contributing

Literate is written in Literate D and you can find the source code in the lit directory. You can also read the source code compiled by Literate here. I am happy to accept pull requests, and if you find any bugs, please report them. Thanks!

More Repositories

1

micro

A modern and intuitive terminal-based text editor
Go
22,579
star
2

generic

A collection of generic data structures written in Go.
Go
1,260
star
3

eget

Easily install prebuilt binaries from GitHub.
Go
708
star
4

knit

A simple and flexible build tool using Lua, similar to make/mk.
Go
172
star
5

multiplix

An operating system kernel for RISC-V and AArch64 SBCs
D
120
star
6

SFML.jl

A binding of the game and multimedia library SFML for Julia
Julia
93
star
7

gpeg

A PEG parsing machine with support for incremental parsing.
Go
75
star
8

perforator

Record "perf" performance metrics for individual functions/regions of an ELF binary.
Go
58
star
9

sregx

A tool and library for using structural regular expressions.
Go
56
star
10

highlight

A Go package for syntax highlighting
Go
54
star
11

literate.vim

Vim plugin for the Literate programming tool
Vim Script
36
star
12

termbox-d

A D wrapper of the TUI library Termbox
D
23
star
13

dotvim

My Vim configuration
Vim Script
20
star
14

AnimatedPlots.jl

Fast animated (and static) plots for Julia
Julia
18
star
15

vim-snake

Snake game written in Vimscript
Vim Script
18
star
16

unionize

A tool for generating unions in Go
Go
16
star
17

flare

Syntax highlighting engine built using GPeg
Go
13
star
18

julialint.vim

Built in Vim linter for Julia
Vim Script
12
star
19

lfi

Lightweight Fault Isolation: Practical, Efficient, and Secure Software Sandboxing
C
12
star
20

mkinfo

Program to fix the terminal entry problem
Go
11
star
21

Chipmunk.jl

A binding of the physics engine Chipmunk for Julia
Julia
9
star
22

riscinator

A tiny 3-stage RISC-V core written in Chisel.
C
9
star
23

make-template

Makefile template for simple C/C++ programs
Makefile
9
star
24

crypt

A tool for making password-protected files
Go
9
star
25

cgc

C garbage collector
C
8
star
26

wasm2bin

Compiler from Webassembly to native binaries
C
8
star
27

SpaceShooter.jl

Julia
7
star
28

clipper

Cross-platform clipboard access in Go
Go
6
star
29

xkvt

A tool for tracing the inputs and outputs of a command
Go
5
star
30

ftdetect

A filetype detection library
Go
5
star
31

rvasm

A simple RISC-V RV32I assembler
Go
4
star
32

JuliaCon-SFML

SFML.jl examples from JuliaCon
Julia
4
star
33

rvsym

A small RISC-V symbolic execution engine
Go
4
star
34

blog-code

D
4
star
35

microsnippets

Lua
4
star
36

ballgame

Go
4
star
37

rope

A rope data structure implemented in Go
Go
4
star
38

ht

Simple hashtable written in C
C
3
star
39

elm-asteroids

Elm
3
star
40

midi

Go
3
star
41

asm

Go
3
star
42

knitja

A tool for converting Ninja build files to Knitfiles
C
3
star
43

julia-jump-game

Julia
3
star
44

homebrew-micro

Ruby
2
star
45

tzu

An experiment in unpredictability.
Go
2
star
46

dpi

D
2
star
47

glob

A Go package for glob matching
Go
2
star
48

install-utils

Shell
2
star
49

armgen

A tool for analyzing the Arm Machine Readable Specification
Go
2
star
50

gpeg-extra

C
2
star
51

riscv-gnu-toolchain-prebuilt

Pre-built Linux binaries for the RISC-V GNU Toolchain
Shell
2
star
52

pios

C
2
star
53

avalon

Go
2
star
54

rpi4

C
2
star
55

quark

QUark Assembly Rewriting Kit
C++
2
star
56

lfi-artifact

2
star
57

armvis

Visualizing the ARM64 instruction set
Go
2
star
58

CarGame

JavaScript
1
star
59

hifive

Simple bare-metal library and example programs for the HiFive 1 Rev B
C
1
star
60

setup-knit

GitHub Action for installing Knit
1
star
61

tanks

Go
1
star
62

interval

Go
1
star
63

sfml

Go
1
star
64

kbd

Go
1
star
65

rustalyzer

Rust
1
star
66

libmemstk

C
1
star
67

literate-micro

Lua
1
star
68

TankGame

JavaScript
1
star
69

axum

A small SoC built around the Ibex processor
C
1
star
70

comp

A tool for finding and executing commands from compile_commands.json
Go
1
star
71

verilator-example

C++
1
star
72

revisor

D
1
star
73

CircuitEvolver

D
1
star
74

bzlatest

C++
1
star
75

CoDI

JavaScript
1
star