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>
37 lines
1.3 KiB
Text
37 lines
1.3 KiB
Text
# ============================================================================
|
|
# qdecl.ludic — a handler whose query lives in a @Queries annotation.
|
|
#
|
|
# @Queries(these: [Battle{hp <= 0 and side == 1}, Pos], on: Foe)
|
|
# handler CleanBattle phase LateUpdate { … }
|
|
#
|
|
# 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 }
|
|
property Pos { x: int = 0, y: int = 0 }
|
|
model Foe { Battle, Pos }
|
|
|
|
handler Seed phase Start {
|
|
spawn Foe { Battle { hp: 3, side: 1 } }
|
|
spawn Foe { Battle { hp: 0, side: 1 } }
|
|
spawn Foe { Battle { hp: -2, side: 0 } }
|
|
}
|
|
|
|
# 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()
|
|
}
|
|
|
|
@Queries(these: [Battle])
|
|
handler Census phase Render {
|
|
print_int(Battle.hp)
|
|
}
|
|
|
|
handler Bye phase Render { quit() }
|
|
}
|