Tools
Every tool on this page —playground, extension, command line and libraries— implements the same five specifications and reports the same error codes. The choice between them does not affect compatibility.
STXT needs no installation to get started. Depending on the intended use:
| Use | Tool |
|---|---|
| Try the language without installing anything | The playground |
| Write documents regularly | The VS Code extension |
Validate from a script, a Makefile or CI |
The stxt command line |
| Read or generate STXT from a program | A library: TypeScript, Java or Python |
Playground
play.stxt.dev is an editor in the browser, designed as a simplified VS Code: several documents at once, their schemas or templates next to them, syntax and validation errors while editing, grammar-driven autocompletion and hover with the definition of each node.
- No installation and no account; the work is kept in the browser itself.
- It includes a seed of example documents.
- A document can be shared with a link that carries the content inside.
It allows following the tutorial without leaving the browser.
VS Code extension
The official extension is
STXT Language (stxt-lang.stxt).
From the extensions view, searching for stxt, or from the terminal:
code --install-extension stxt-lang.stxt
Features:
- Syntax errors in real time, and schema errors when a grammar applies.
- Semantic highlighting driven by the parser itself.
- Completion with the nodes the schema allows and the values of an
ENUM. - Hover information: node, canonical name, type, values and description.
- Go to definition (F12): from a node to the
Node:of its schema, or to its line inside theStructureof its template. - Document formatting.
- Schema and template resolution from the
.stxt/directories of the project, the user and the system, as described in the discovery reference.
Command line
The stxt command is the interface for scripts, Makefiles and continuous
integration pipelines. It is published on npm as
@stxt-lang/cli and requires
Node 20 or newer.
npm install -g @stxt-lang/cli
stxt --version
Without a permanent installation, through npx:
npx @stxt-lang/cli validate docs/
The commands:
| Command | What it does |
|---|---|
stxt validate |
Parses and validates one or more files or directories; no output when all pass |
stxt format |
Reformats (--tabs / --spaces); --check for CI, --write to save |
stxt describe |
Prints the logical tree of a document as JSON (STXT-TREE-SPEC) |
stxt schemas |
Shows which schemas and templates apply in a directory, and from which level |
stxt install |
Installs a definition into ./.stxt, ~/.stxt or the system level |
A CI example, which fails if any document does not validate or is not well formatted:
stxt validate --recursive docs/
stxt format --check --recursive docs/
The exit code distinguishes document errors (1) from command misuse (2), so it
can be used directly from a script. No command rewrites files without --write.
Every option, output and exit code is in the
command-line reference.
Libraries
This portal maintains three official implementations —TypeScript/JavaScript, Java and Python—, and we hope many more will appear for other languages.
TypeScript / JavaScript
@stxt-lang/core on npm. It is
the parser the extension, the command line and the playground run on. The full
guide —tree, validation, resolution, canonical JSON, writing— is in
the TypeScript library.
npm install @stxt-lang/core
A minimal example:
import { Parser, InlineNode } from '@stxt-lang/core';
const result = new Parser().parseResult(text);
for (const error of result.getErrors()) {
console.error(`line ${error.line} [${error.code}]: ${error.message}`);
}
const root = result.getNodes()[0];
if (root instanceof InlineNode) {
console.log(root.getChild('Title')?.getText());
}
Java
dev.stxt:stxt-core
on Maven Central. Java 17 or newer; automatic module dev.stxt. The full guide is
in the Java library.
<dependency>
<groupId>dev.stxt</groupId>
<artifactId>stxt-core</artifactId>
<version>1.0.0</version>
</dependency>
Or with Gradle:
implementation 'dev.stxt:stxt-core:1.0.0'
Python
stxt on PyPI. Pure Python, 3.10 or newer. The full
guide is in the Python library.
pip install stxt
A minimal example:
from stxt import Parser, InlineNode
result = Parser().parse_result(text)
for error in result.get_errors():
print(f"line {error.line} [{error.code}]: {error.message}")
root = result.get_nodes()[0]
if isinstance(root, InlineNode):
print(root.get_child("Title").get_text())
Source code
The whole ecosystem lives in the stxt-lang organization on GitHub, under the MIT license:
| Repository | Contents |
|---|---|
| stxt-lang | This site: the specifications, the conformance kit and the example corpus |
| stxt-js | @stxt-lang/core, the TypeScript library |
| stxt-java | dev.stxt:stxt-core, the Java library |
| stxt-python | stxt, the Python library |
| stxt-cli | @stxt-lang/cli, the command line |
| stxt-vscode | The VS Code extension |
| stxt-play | The playground |
Questions, ideas and anything about the language itself go to the discussions of the organization; bugs, to the issues of the repository of the tool concerned.