@typedblite/language
Langium grammar, generated AST, and language services for TypeQLite — the TypeQL 3.x dialect that TypeDBLite speaks.
What this package provides
Section titled “What this package provides”- Grammar (
src/typeqlite.langium) — the authoritative Langium grammar definition for TypeQLite 3.x. - Generated AST (
src/generated/ast.ts) — typed node interfaces andis*/as*type guards for every grammar production, generated bylangium generateand given doc comments byscripts/document-generated.mts(thelangium-generatetarget runs both). - Module (
typeqlite-module.ts) — Langium DI container with all TypeQLite services wired up. - Synchronous validation (
typeqlite-validate-sync.ts,typeqlite-validator.ts) — parse-time constraint checks that run synchronously, as the runtime requires. - Validation codes (
typeqlite-validation-codes.ts) — stable string identifiers for every validation rule; consumed by the runtime’sDiagnosticCodeto avoid a parallel vocabulary. - Annotation admissibility (
typeqlite-annotations.ts) — table of which annotations are valid at which positions (type,sub, trait, value type). - Scope provider (
typeqlite-scope.ts) — resolves cross-references; role names are scoped to their relation, so two relations may eachrelate member. - Formatter (
typeqlite-formatter.ts) — canonical formatting for.typeqlitefiles. - Semantic tokens (
typeqlite-semantic-tokens.ts) — token classifications for editor syntax highlighting. - Editor services — a workspace-wide schema (
typeqlite-scope-computation.ts), query-label resolution (typeqlite-labels.ts), outline and hover (typeqlite-navigation.ts), completion, rename and quick fixes. The VS Code extension runs them in a language server. 🔴 The runtime uses only the parser andvalidateSync, so a check registered inValidationRegistryis a runtime rule too (ADR-008 D2). - TextMate grammar (
syntaxes/typeqlite.tmLanguage.json, imported as@typedblite/language/typeqlite.tmLanguage.json) — for editors and highlighters that use TextMate grammars, and underneath the semantic tokens in one that has both. Generated byscripts/generate-textmate.mtsfrom the grammar’s keywords, each scoped by what it is (typeqlite-textmate.ts), with the scopes TypeDB’s TypeQL grammar uses.
Installation
Section titled “Installation”npm install @typedblite/languageInside this repository it is a workspace dependency of @typedblite/runtime and of the VS Code
extension. Build it with npm exec nx -- run typeqlite-language:build.
Parse, then validate. This is exactly what the runtime does with every statement:
import { EmptyFileSystem } from 'langium';import { createTypeQLiteServices, validateSync, isEntityDef, type TypeQLiteFile } from '@typedblite/language';
const { TypeQLite } = createTypeQLiteServices(EmptyFileSystem);
const result = TypeQLite.parser.LangiumParser.parse<TypeQLiteFile>(` define entity person, owns name @key; attribute name, value string;`);const syntaxErrors = [...result.lexerErrors, ...result.parserErrors]; // []const diagnostics = validateSync(TypeQLite, result.value); // [] — every validator rule, synchronouslyconst entities = result.value.clauses .flatMap((clause) => ('definitions' in clause ? clause.definitions : [])) .filter(isEntityDef); // [person]result.value is the AST: typed node interfaces with is* type guards for every production. It is
not linked: the parser path never builds a LangiumDocument, so cross-references are not
resolved. Linking, scoping and the workspace index are for language-server use, where
createTypeQLiteServices is given a real file system and Langium’s document builder.
File extensions
Section titled “File extensions”| Extension | Use |
|---|---|
.typeqlite |
Schema and query files |
.tql |
Alias |
Language ID: typeqlite
Regenerating the AST
Section titled “Regenerating the AST”src/generated/ is build output and is not committed. The build, test and typecheck
targets regenerate it first. After editing the grammar, regenerate it yourself so that tools running
from source see the change:
npm exec nx -- run typeqlite-language:langium-generateCommit the grammar (src/typeqlite.langium, src/terminals.langium), never the generated files.
Adding a TypeQLite construct walks through the
whole path.
Synchronous validation
Section titled “Synchronous validation”Langium wraps every registered validation check in an async function internally. SyncValidationRegistry overrides that wrapper to keep the check’s own synchronous result synchronous. The runtime calls validateSync, which never returns a Promise. A rule that returns a Promise is surfaced as a validation error rather than silently awaited.
Grammar scope
Section titled “Grammar scope”TypeQLite 3.x implements the subset required by real production schemas and by TypeDB’s behavior specification (typedblite-conformance/spec/). A construct is added only when a real caller needs it. The rule is:
Find the caller first. What is here is what callers use — not what TypeDB has.
npm exec nx -- run typeqlite-language:testTest files live in test/ with .spec.ts extension. The spec-backgrounds suite (test/spec-backgrounds.spec.ts) uses the vendored TypeDB behavior specification as acceptance tests for the grammar.
TypeDBLite is an independent open-source project, built on TypeDB with thanks. It is not affiliated with, sponsored by, or endorsed by TypeDB Ltd. Released under the MPL-2.0 license.