feat(lang): L9 resource files - registry ... from
registry NAME of RECORD [as PREFIX] from "file.lres" fills a registry from a data
file of key { field: value } entries, read at compile time with the record as its
schema: every entry is checked like a def, errors name the resource file's line,
nested records and lists of them are bare { } / [{ }] typed by their fields, and
values are expressions in the registry's module. The entries are compiled in, so
nothing parses at start-up and a build that succeeds has validated its resources.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7e7f3ab297
commit
e543525eb7
15 changed files with 46229 additions and 44690 deletions
11
examples/lang/data/tools.lres
Normal file
11
examples/lang/data/tools.lres
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# tools.lres - the tools a camp keeps, read by resources.ludic's registry when it is compiled
|
||||
axe {
|
||||
name: "Axe"
|
||||
weight: 1.5
|
||||
uses: [{ verb: "Chop", minutes: 20 }, { verb: "Split", minutes: 10 }]
|
||||
}
|
||||
lantern {
|
||||
name: "Lantern"
|
||||
weight: 0.75
|
||||
uses: []
|
||||
}
|
||||
24
examples/lang/resources.ludic
Normal file
24
examples/lang/resources.ludic
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# resources.ludic — L9: a registry whose entries live in a resource file. `from` names the file;
|
||||
# it is read when the program is compiled, every entry checked against the record (the schema),
|
||||
# and compiled in - so a mistake is a compile error at the resource file's line, and nothing parses
|
||||
# at start-up. A field whose type is a record, or a list of them, takes a bare `{ ... }`.
|
||||
#
|
||||
# Running it prints: 2 Axe 2 Split 10 0 1
|
||||
program Resources {
|
||||
numbers float
|
||||
property Use {
|
||||
verb: string = ""
|
||||
minutes: int = 0
|
||||
}
|
||||
property Tool {
|
||||
key: string = ""
|
||||
name: string = ""
|
||||
weight: float = 0.0
|
||||
uses: []Use = null
|
||||
}
|
||||
registry Tools of Tool as TL from "data/tools.lres"
|
||||
entry {
|
||||
let axe = Tools[TL_AXE]
|
||||
print(`{TL_COUNT} {axe.name} {len(axe.uses)} {axe.uses[1].verb} {axe.uses[1].minutes} {len(Tools[TL_LANTERN].uses)} {tools_find("lantern")}`)
|
||||
}
|
||||
}
|
||||
4
examples/rejected/data/bad_tools.lres
Normal file
4
examples/rejected/data/bad_tools.lres
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
axe {
|
||||
name: "Axe"
|
||||
weight: "heavy"
|
||||
}
|
||||
11
examples/rejected/resource_field.ludic
Normal file
11
examples/rejected/resource_field.ludic
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# L9: a resource file's entries are checked against the record, at the file's own line
|
||||
program ResourceField {
|
||||
numbers float
|
||||
property Tool {
|
||||
key: string = ""
|
||||
name: string = ""
|
||||
weight: float = 0.0
|
||||
}
|
||||
registry Tools of Tool from "data/bad_tools.lres"
|
||||
entry { print(TOOLS_COUNT) }
|
||||
}
|
||||
6
examples/rejected/resource_missing.ludic
Normal file
6
examples/rejected/resource_missing.ludic
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# L9: a registry's resource file must exist
|
||||
program ResourceMissing {
|
||||
property Tool { key: string = "" }
|
||||
registry Tools of Tool from "data/no_such.lres"
|
||||
entry { print(TOOLS_COUNT) }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue