-
Notifications
You must be signed in to change notification settings - Fork 0
Quick Start
This page takes a new project from an empty file to validated vocabulary, generated source, and editor diagnostics.
Lexicon is a Swift package. The current package declares Swift 6.3, Swift language mode 6, macOS 15, and iOS 18.
git clone https://github.com/ollieatkinson/Lexicon.git
cd Lexicon
swift build --product lexicon
swift build --product lexicon-generate
swift build --product lexicon-lspDuring local development you can run tools through SwiftPM:
swift run lexicon --help
swift run lexicon-generate --help
swift run lexicon-lsp --helpFor editor integrations, build a release language server and put it on PATH:
swift build -c release --product lexicon-lsp
cp .build/release/lexicon-lsp /usr/local/bin/lexicon-lspIf you do not want to copy the binary, configure your editor with the absolute path to .build/release/lexicon-lsp.
Create commerce.lexicon. Indentation is significant and uses tabs.
# Shared commerce vocabulary.
> API, UI, analytics, and support can keep local words while sharing meaning.
commerce:
type:
boolean:
string:
api:
order:
submit:
+ commerce.type.boolean
? true
ui:
checkout:
button:
primary:
+ commerce.api.order.submit
analytics:
event:
checkout_started:
+ commerce.ui.checkout.button.primary
support:
ticket:
status:
+ commerce.type.string
? "open"
This says:
-
commerce.api.order.submitis a boolean capability. -
commerce.ui.checkout.button.primaryis typed by the API submit capability. -
commerce.analytics.event.checkout_startedis connected to the UI button concept. -
commerce.support.ticket.statushas a default string value. - Notes use
>and are intended for readers of the vocabulary. - Comments use
#and are authoring/tooling annotations.
swift run lexicon validate commerce.lexicon
swift run lexicon lint commerce.lexicon
swift run lexicon inspect commerce.lexicon commerce.ui.checkout.button.primary
swift run lexicon tree commerce.lexicon commerce --depth 4 --metadataValidation and inspection commands print structured JSON so scripts and editor tooling can consume the output.
swift run lexicon search commerce.lexicon submit button --mode hybrid --limit 5
swift run lexicon search commerce.lexicon support status --mode token --limit 5
swift run lexicon refs commerce.lexicon commerce.ui.checkout.button.primaryUse hybrid as the default search mode. Use token when you are looking for exact-ish path/name matches.
Generate one target at a time when two targets share an extension. For example, swift and swift-standalone both emit .swift.
swift run lexicon-generate commerce.lexicon --type swift -o Generated/Commerce
swift run lexicon-generate commerce.lexicon --type go --go-package commerce -o Generated/commerce
swift run lexicon-generate commerce.lexicon --type rust -o Generated/commerce
swift run lexicon-generate commerce.lexicon --type ts -o Generated/commerce
swift run lexicon-generate commerce.lexicon --type json,json-ld -o Generated/commerceThe -o/--output value is a path without the final extension. Lexicon appends the generator extension, such as .swift, .go, .rs, .ts, .json, or .jsonld.
Create lexicon-lsp.json at the workspace root:
{
"lexicon": "commerce.lexicon"
}The language server composes imports and indexes the live graph. It then provides completions and unknown-path diagnostics for:
- Lexicon document references, such as
+ commerce.type.boolean. - Go exact-path calls, such as
l("commerce.api.order.submit"). - Rust exact-path macros, such as
l!(commerce.api.order.submit).
See Editor Support for editor-specific setup.
.package(
url: "https://github.com/ollieatkinson/Lexicon.git",
branch: "trunk"
)Then depend on the products you need:
.product(name: "Lexicon", package: "Lexicon")
.product(name: "SwiftLexicon", package: "Lexicon")
.product(name: "LexiconGenerators", package: "Lexicon")Use Lexicon to parse, compose, inspect, and edit documents. Use SwiftLexicon when your generated Swift source depends on the shared runtime. Use LexiconGenerators when you are integrating generation into your own tool.