Phase 6b: a handler's query is @Queries only; drop the signature clauses
The handler-signature `query (vars) [terms] where …` clause and the
`reads`/`writes` clauses overlapped the `@Queries` annotation (and each other):
two ways to attach a query to a handler. Consolidated on the decorator.
- parse_system no longer parses `query`/`reads`/`writes` clauses; it keeps the
postfix `@anno(...)` channel and `phase`. A handler's query is the prefix
`@Queries(these: [...], on: Model)` annotation. Data-access hints are now
`@Reads(...)`/`@Writes(...)` — absorbed by the generic annotation skipper,
same parse-and-reserve status the old clauses had.
- The inline `for (…) in query […] where …` statement is unchanged and still
covers cross-property constraints / multiple kind filters. `query` stays a
keyword there (now dispatched via is_id so the vocabulary check sees it).
examples/hello.ludic and examples/qdecl.ludic migrated to `@Queries` (qdecl now
demonstrates a per-property constraint + `on:` tag); outputs unchanged
(4 4 10 3 / 0 3 -2). LANGUAGE.md handler sections rewritten. Vocabulary: drop
`reads`/`writes` from CLAUSE (ludic_syntax.h, grammar, LudicTokens.kt).
Reseeded (21931 lines); C-free fixpoint holds; goldens identical; 17/17;
vocab + doc-fences clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
da48dc8499
commit
3fd599ce47
10 changed files with 2829 additions and 3071 deletions
|
|
@ -15,13 +15,12 @@ program Hello {
|
|||
}
|
||||
}
|
||||
|
||||
# a system can declare the entities it operates on: the body then runs once
|
||||
# per match, with the components bound and self() giving that entity.
|
||||
handler Move phase FixedUpdate
|
||||
query (p, v) [Pos, Vel]
|
||||
{
|
||||
p.x = p.x + v.dx
|
||||
p.y = p.y + v.dy
|
||||
# a handler declares the entities it operates on with @Queries: the body then
|
||||
# runs once per match, each property bound by name and self() giving that entity.
|
||||
@Queries(these: [Pos, Vel])
|
||||
handler Move phase FixedUpdate {
|
||||
Pos.x = Pos.x + Vel.dx
|
||||
Pos.y = Pos.y + Vel.dy
|
||||
}
|
||||
|
||||
handler Report phase Update {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
# ============================================================================
|
||||
# qdecl.ludic — a system whose query lives in its signature.
|
||||
# qdecl.ludic — a handler whose query lives in a @Queries annotation.
|
||||
#
|
||||
# system CleanBattle phase LateUpdate
|
||||
# query (b, p) [Battle, Pos, {Foe}] where b.hp <= 0
|
||||
# { … }
|
||||
# @Queries(these: [Battle{hp <= 0 and side == 1}, Pos], on: Foe)
|
||||
# handler CleanBattle phase LateUpdate { … }
|
||||
#
|
||||
# is the same thing as writing `for (b, p) in query [...] where ... { … }` around
|
||||
# the whole body — the loop header just moves into the declaration. The body runs
|
||||
# once per matching entity, and self() is that entity.
|
||||
# is the same thing as writing `for (Battle, Pos) in query [Battle, Pos, {Foe}]
|
||||
# where Battle.hp <= 0 and Battle.side == 1 { … }` around the whole body — the
|
||||
# loop header moves into the annotation. Each property binds by name, the body
|
||||
# runs once per matching entity, and self() is that entity.
|
||||
# ============================================================================
|
||||
program QueryDecl {
|
||||
property Battle { hp: int = 0, side: int = 0 }
|
||||
|
|
@ -20,17 +20,17 @@ program QueryDecl {
|
|||
spawn Foe { Battle { hp: -2, side: 0 } }
|
||||
}
|
||||
|
||||
handler CleanBattle phase LateUpdate
|
||||
query (b, p) [Battle, Pos, {Foe}] where b.hp <= 0 and b.side == 1
|
||||
{
|
||||
print_int(p.x)
|
||||
# a per-property constraint `Battle{...}` qualifies its bare fields to that
|
||||
# property; `on: Foe` adds the {Foe} kind filter.
|
||||
@Queries(these: [Battle{hp <= 0 and side == 1}, Pos], on: Foe)
|
||||
handler CleanBattle phase LateUpdate {
|
||||
print_int(Pos.x)
|
||||
despawn self()
|
||||
}
|
||||
|
||||
handler Census phase Render
|
||||
query (b) [Battle]
|
||||
{
|
||||
print_int(b.hp)
|
||||
@Queries(these: [Battle])
|
||||
handler Census phase Render {
|
||||
print_int(Battle.hp)
|
||||
}
|
||||
|
||||
handler Bye phase Render { quit() }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue