Your first document
We will describe a stationery catalog containing two products. The purpose is to make the information explicit and inspect the model that Nexus Script builds.
Prepare a folder
Use a current Nexus installation with NexusScript available on PATH.
NexusScript /help prints the command-line options. The CLI is available on
Windows and Linux; the commands below use the same arguments on both.
Create an empty folder for this chapter. Save this as Catalog.nxscript:
Catalog Shop {
Title: "Corner Stationery";
Currency: USD;
Product Notebook {
Title: "Pocket notebook";
PriceCents: 450;
}
Product Pencil {
Title: "Graphite pencil";
PriceCents: 90;
}
}
Read the first declaration as “a Catalog named Shop.” Its braces contain the
information belonging to Shop. Title and Currency are properties. Each
property has a colon, a value, and a terminating semicolon.
Product Notebook and Product Pencil are child definitions. They have their
own properties and their own identities within Shop. Their closing braces do
not take semicolons. This distinction lets a reader see where a value ends and
where a nested definition ends.
Notebook is the definition's name, used to address it. "Pocket notebook"
is the value of its Title property, used by our catalog application for display.
Changing the title does not rename the definition.
Catalog, Product, Title, and PriceCents are vocabulary we chose for this
model. No dialect or built-in product type is required to write this document.
Compile and inspect
From that folder, run:
NexusScript /input=Catalog.nxscript /output=Catalog.json
Open Catalog.json. Its domain content is:
{
"Shop": {
"Title": "Corner Stationery",
"Currency": "USD",
"Notebook": { "Title": "Pocket notebook", "PriceCents": "450" },
"Pencil": { "Title": "Graphite pencil", "PriceCents": "90" }
}
}
This display omits the actual output's _nx metadata so the structure is easy
to see. Metadata records such things as kinds and source locations; it does not
replace your domain properties. Artifacts explains the full output.
Notice that JSON uses Shop, Notebook, and Pencil as keys. The language does
not invent a Products wrapper from the kind Product.
Also notice that 450 is emitted as text. Nexus Script's scalar data is text;
a dialect or consumer can require that text to represent an integer. No price
calculation or currency conversion happened during compilation.
Change the model
Change Notebook's PriceCents to 500 and compile again. Only the corresponding
effective value changes. Add a third Product with another name and it becomes
another child of Shop.
Now imagine that the catalog has a featured product, several products share defaults, and different regions need different prices. References, composition, and targets will express those relationships in the following chapters.
Continue with Structure, values, and identity.