GEML block types, illustrated · page 2 of 5 · spec 1.0 · 中文

GEML Blocks Illustrated · code and data

This page covers code and data. They share a page because they are mirror images: code holds text the processor never interprets, data holds a value that must parse; the two share one src= route syntax, yet weigh "cannot resolve" in opposite ways. Each rule names its source; the right-hand side is measured output from geml check, geml get and --to html.

Board

9 rules, each with its source and status

Specified written into the specification. GEP draft defined by a proposal, implemented on this branch, not yet in the spec. Impl. gap none found on this page.

Specified 8 GEP draft 1
RuleSourceStatus
Shared by both
1One route syntax: src=<path>[#L<start>[-<end>]], 1-based and inclusive; resolved relative to the document, or to --root when given; http(s) is fetched by the renderer, every other scheme is refused.§3.3 · §9.4Specified
2One attribute, two weights: an unresolvable code route is a warning (the block describes a region of code somewhere; the document stands without the sources), an unresolvable data route is an error (the value is what the document promised). A stale range is an error for both.§3.3 · §3.2Specified
3Neither may carry src= and a body together (code-src-and-body, data-src-and-body errors). A code route has no extension gate; a data route must be .json/.jsonl.§3.3 · §3.2 · A.5Specified
code
4Raw body; lang= is only a label; the body is never run. Renders as <pre><code class="language-xx">.§3 · §9.1Specified
5src=<path>[#L<s>[-<e>]] names the code shown. Src with a body: error; a drifted range: error; unresolvable: warning (the graph stays valid); a disallowed scheme: error.§3.3 · A.5Specified
data
6The value tree (JSON's value domain). json by default, jsonl one value per line with blank lines ignored. A body that does not parse is a data-parse error naming the line.§3.2 · A.5Specified
7yaml/toml are reserved names: with no engine the body is kept, a warning is emitted, and the processor never guesses. An unknown format degrades the same way. csv is not a data format.§3.2Specified
8src= and a body are mutually exclusive (error); the file must be .json/.jsonl; schema= is reserved, a malformed shape is an error, and nothing validates against it.§3.2 · A.5Specified
9#cfg["tags"][1], #log[1]["t"] read one node of the value tree by coordinate.GEP-0011GEP draft
code

code: the text itself, or a route to a region of source

The body is text and is never run (§9.1). Instead of copying code, src= can point at a file and a line range, and drift is caught.

An inline body and four fates of src= Specifiedhelper.js has three lines.
GEML · p3-code.geml
=== code {#inline lang=ts caption="Inline body"}
export const x = 1;
===
=== code {#routed lang=js src=helper.js#L1-2}
===
=== code {#both lang=js src=helper.js}
body and src together
===
=== code {#drift lang=js src=helper.js#L40-50}
===
=== code {#missing lang=js src=nowhere.js}
===
=== code {#scheme lang=js src=ftp://x/y.js}
===
geml check · --to html
error: code: carries both `src=` and an inline body; exactly one
  is permitted (line 11)
error: code source `helper.js#L40-50`: the file has 3 line(s), so
  lines 40-50 no longer exist — the range is stale (line 14)
warning: cannot resolve code source `nowhere.js` — not checked (line 16)
error: code source `ftp://x/y.js` names a disallowed URL scheme (line 18)
3 error(s), 1 warning(s)
ts · #inlineexport const x = 1;
js · #routed ← helper.js#L1-2export const a = 1; export const b = 2;
js · #drift(empty: the range drifted, nothing is fetched)
Route
§3.3: <path>[#L<start>[-<end>]], 1-based, inclusive. Resolved relative to the document, and also relative to --root when one is named, never outside §9.4's confinement.
Weights
Unresolvable is only a warning: a code block describes "a region of code at a location"; a document whose sources are absent (a published code graph, another checkout) still stands, merely unchecked. A stale range is an error: catching it is the point of checking a route. Src with a body and a disallowed scheme are errors too.
Contrast
data's src= is an error when unresolvable (§3.2): its value is exactly what the document promised, and failing to load it breaks the promise. The two types weigh the same attribute oppositely, each for a reason.
data

data: a verified value tree

Added by GEP-0005. code carries text that must not be interpreted; data carries a value that must parse.

json by default, jsonl line by line, one node by coordinate Specified coordinates GEP-0011
GEML · from p5-data.geml
=== data {#cfg}                       %% format defaults to json
{"name": "geml", "tags": ["a", "b"], "n": 3}
===
=== data {#log format=jsonl}
{"t": 1, "ok": true}

{"t": 2, "ok": false}                  %% blank lines ignored; a block appended at EOF is a new record
===
=== data {#ext src=rows.json}          %% the content lives in a file; the block is its addressable view
===
geml get · --to html
$ geml get p5-data.geml '#cfg["tags"][1]'
b
$ geml get p5-data.geml '#log[1]["t"]'
2
figure #cfg › pre.data-src data-format="json"
{"name": "geml", "tags": ["a", "b"], "n": 3}
figure #ext · file contents loaded
[ {"id": 1, "v": 10}, {"id": 2, "v": 20} ]
Model
§3.2: the body is raw at scan time (fences only delimit), then a format engine parses it into the block's value, exposed in the document model. json is the default because it is the value tree's own serialization, the one a zero-dependency processor can always verify.
jsonl
The record-stream form: a document is a flat sequence of blocks, so a complete data block appended at end of file is always a valid continuation. jsonl's blind-append ergonomics, with ids, verification and chart binding.
Coordinates
GEP-0011: unnamed inner units are addressed with bracket coordinates; [ cannot occur in a legal id, so nothing is confused. geml list does not enumerate coordinates; the author constructs them. Implemented on this branch, not yet in the spec.
Five ways to fail SpecifiedThree errors and three warnings; the boundary is exactly "can the value be verified".
GEML · from p5-data.geml
=== data {#bad}
{"name": "geml",                       ← not one complete JSON value
===
=== data {#y format=yaml}          %% reserved name
name: geml
===
=== data {#both src=rows.json}
{"x": 1}                               ← src and body together
===
=== data {#sch schema=not-a-ref}
{"x": 1}
===
=== data {#csvish format=csv}
a,b
===
geml check
error: data: body is not valid JSON (Expected double-quoted
  property name in JSON at position 16 (line 1 column 17)) (line 14)
warning: data: no `yaml` engine in this processor; body kept raw,
  not verified (line 16)
warning: data: no `toml` engine in this processor; body kept raw,
  not verified (line 20)
error: data: carries both `src=` and an inline body; exactly one is
  permitted (the body wins here) (line 25)
error: data: `schema=not-a-ref` must name a block (`#id`) or a GEML
  document (`doc.geml[#id]`) (line 28)
warning: unknown data format `weird`; body kept raw (line 31)
warning: unknown data format `csv`; body kept raw (line 34)
3 error(s), 4 warning(s)
error
A body that does not parse, src with a body, a malformed schema reference: all three are the document misspeaking. data-parse names the line.
warning
yaml/toml are reserved names: without an engine the body is kept, not verified, never guessed — the same degradation as an unknown diagram format (§7). An unknown format likewise. csv is not a data format: it is not self-describing (delimiter, header and quoting are parameters) and only means something against a column model, so it is a table format (§6).
This build
A recent commit on this branch adds a yaml engine, yet this build still reports "no yaml engine"; it may not be wired in. Recorded as an observation, not a conclusion.
Evidence

Probe files and measured output

All run with the repository's current build, node geml-parser/dist/geml.js. The probe files live in the session scratch directory; their full text appears on the left of each figure above.

ProbeCoverscheck resultWhere on this page
p3-code.geml · helper.jsinline body, route, src with body, drifted range, unresolvable, disallowed scheme3 error 1 warningcode
p5-data.geml · rows.jsonjson, jsonl, src, bad JSON, yaml, toml, src with body, schema, unknown format, csv, coordinates3 error 4 warningdata