Proposal for prolog-inspired ECS query DSL that can resolve components as well as entity relationships. Not a formal syntax/grammar definition.
. // Self. Indicates iterated over entity or entity for given (arche)type
Entity // Entity identifier
X // Variable (all caps identifier)
_ // Anonymous variable. Indicates that query is not interested in all permutations.
[Position] // . with Position
[Position, Velocity] // . with Position, Velocity
[(Likes, Bob)] // . with Likes Bob
. // Select entities with self
X // Select entities with X
Component // Select entities with Component
Component(.) // Select entities with Component
Component(X) // Constraint on X: must have Component
Position, Velocity // Select entities with Position and Velocity
Position || Velocity // Select entities with Position or Velocity
Position || [Speed, Velocity] // Select entities with Position or (Speed and Velocity)
Likes(., Subject) // Select entities with (Likes, Subject)
Likes(Object, .) // Select entities for Object with (Likes, .)
.(Object) // Select all entities that Object has
Position
Evaluation:
foreach . with [Position]:
yield .
Position(.)
Evaluation:
foreach . with [Position]:
yield .
.
Evaluation:
foreach . with [.]:
yield .
Position, Velocity
Evaluation:
foreach . with [Position, Velocity]:
yield .
Likes(., Bob)
Evaluation:
foreach . with [(Likes, Bob)]:
yield .
Likes(Bob, .)
Evaluation:
Bob with [(Likes, .)]
yield .
Likes(., X)
Evaluation:
foreach . with [(Likes, X)]:
foreach X:
yield ., X
Likes(X, .)
Evaluation:
foreach X with [(Likes, .)]
foreach .:
yield ., X
.(Bob)
Evaluation:
Bob with [.]:
foreach .:
yield .
.(X)
Evaluation:
foreach X with [.]:
foreach .:
yield ., X
X(.)
Evaluation:
foreach . with [X]:
foreach X:
yield ., X
Likes(., X), Likes(X, .)
Evaluation:
foreach . with [(Likes, X)]
foreach X with [(Likes, .)]:
yield ., X
Likes(., X), Likes(X, Y), Likes(Y, .)
Evaluation:
foreach . with [(Likes, X)]
foreach X with [(Likes, Y)]:
foreach Y with [(Likes, .)]
yield ., X, Y