Skip to content

Turtle formatter pretty - #35

Merged
ajuvercr merged 6 commits into
mainfrom
turtle-formatter-pretty
Oct 14, 2026
Merged

ajuvercr merged 6 commits into
mainfrom
turtle-formatter-pretty

Conversation

@ajuvercr

Copy link
Copy Markdown
Collaborator

The biggest change is using the rdf-parsers formatters for turtle, trig, sparql and n3.

ajuvercr and others added 5 commits October 14, 2026 11:26
Layout decisions are now made while building a `pretty` document, and
rendering is left to pretty's group/fits algorithm. Hard lines propagate
breaks to enclosing groups, so nested multi-line blank nodes and
collections lay out correctly without rewinding the output buffer.

- single-PO blank nodes stay inline when they fit, else break after `[`
- multi-PO blank nodes always break after `[` (Style knob)
- collections stay inline when they fit, else one item per line
- object lists of simple terms break all-or-nothing; lists containing
  nested structures keep `], [` together

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Formatting:
- Point rdf-parsers at the local checkout (../rdf-parsers), which has the
  pretty-based generated formatters.
- Turtle formats from the stored syntax tree with rdf-parsers' TurtleHook;
  a small hook on top keeps rewriting prefix/base declarations to the
  configured `prefix_format`. The hand-written formatter and its `pretty`
  dependency are gone.
- TriG picks up the new formatter through the dependency.
- SPARQL gets a format system: the parse stores the syntax tree on a clean
  parse, and formatting is opt-in via `format.sparql`.

Config:
- `format` moves into LocalConfig, so it also works from
  ~/.config/swls/config.json and .swls/config.json; later sources override
  the toggles they set.
- Invalid initializationOptions are reported (log + client output) instead
  of silently resetting every setting.
- README documents `format`, `prefix_format` and source precedence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`.ru` files hold SPARQL updates, which failed to parse as queries, so
they showed false syntax errors and were never formatted. They are now
parsed with the update grammar. Also covers the new N3 formatter from
rdf-parsers with a test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Turtle, TriG, SPARQL, N3 and JSON-LD now format unless disabled with
`format.<language>: false`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ajuvercr

Copy link
Copy Markdown
Collaborator Author

This fixes #34

@ajuvercr
ajuvercr merged commit 12054cb into main Oct 14, 2026
2 checks passed
@ajuvercr
ajuvercr deleted the turtle-formatter-pretty branch October 14, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant