summaryrefslogtreecommitdiffhomepage
path: root/gleam/README.md
blob: 42c3e576a9b4504ff34f519dd6f0a46f20ff6da8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# ssp-reader, in Gleam

Reads a `.ssp`, the object-centric document abstraction written as text,
and says what it found and what it did not understand.

**Written from the specification alone**, as an experiment in whether that
specification suffices:

- `ssp-format-specification.md`, from the **sisudoc-abstraction-format**
  specification
- `ocda-model.md`, from the same

No reference was made to spine's emitter or to the D reader while writing
it. The constants it carries (the sixteen kinds, the nine sections, the
four preamble blocks, the 43 properties in their emitted order) were taken
from the specification's own tables.

## Building and running

```sh
nix build                 # the reader, as a single-file escript
./result/bin/ssp_reader <file.ssp>
```

`nix build` works **sandboxed and without network**. There is no Gleam
builder in nixpkgs and `gleam build` fetches from Hex, so the build uses
nix-gleam's builder, kept in `nix-gleam/` (MIT, see its README), which
fetches each Hex package on its own by the checksum `manifest.toml` already
carries. There is no hash in `flake.nix` to keep up to date. The result
needs only what it carries: run it with an empty environment and it works.

For development:

```sh
nix develop               # gleam, erlang, rebar3
gleam run -- <file.ssp>
gleam run -- --outline <file.ssp>
gleam run -- --report-unknown <file.ssp>
gleam run -- --any-version <file.ssp>
```

## What it does

- Reads the version banner and **checks the major part**, refusing a major
  it does not know (specification section 2.1). `--any-version` overrides.
- Parses the four preamble blocks, the nine sections, and the object
  records: declaration line, properties, text.
- `--outline` prints the headings indented by level.
- `--report-unknown` lists every property it did not use, with counts.

## Agreement with the D reader

Both implementations were run over the 36 document reference collection
and **agree on the section counts of all 36**.

## Tests

```sh
gleam test
```

Ten, against small literals rather than files, since the parser is a pure
function from text to a document. Each names the specification section it
holds the parser to: the version banner, the `% Source:` line, `@source`
being preamble and not a section, the object declaration, text line order,
ancestors as numbers, that a `comment` object does not render, that an
unused property is counted rather than dropped, and that a line of no known
shape is counted.

## What it does not do

- The `.ocda.db`, which would want an Erlang sqlite binding.
- HTML, JSONL or plain-text output.
- Packaging as an escript, so it needs `gleam run`.

## Layout

```
src/ssp_reader.gleam   the program: arguments, version gate, output
src/ssp/types.gleam    the document, the object, the version rule
src/ssp/parse.gleam    the parser, a fold over the lines
```