Need: a language for serialisation supporting set operations

This is not a rust problem per se, but it would be great to learn of any options that may already exist.

```Items`` have attributes like Color, weight, category or weight etc. There is a table in the EAV format which gives the attribute values for each entity.

What I”d like to do is read a config file which specifies groupings of items, in a flexible manner, e.g in pseudo-code.

Red_Items: item.color == “Red”
Heavy_Items: item.weight > 10
Heavy_Red_items: Intersect(red_items, heavy_items)

I’d like this config file to be easy to read, but providing for sufficient flexibility in terms of building groups etc. I’m not sure if I can use toml for this purpose since it seems we cannot define groups in terms of operations on other groups - but I could be mistaken.

That suspiciously looks like you are trying to replicate database operations. Can you specify what you are planning to do with the config file afterwards? I'm thinking that probably using a relational database with its own query language could be the solution.

1 Like

Possibly yes, but I'd prefer a script to make it more usable for end-users. The data about attributes etc come from the database, which possibly contains a very large set of items and attribute combinations. The config file specifies a subset which is used by the application to perform the required computations.

While I could write SQL to specify the subset, I feel it is not the proper tool for the job -- a scripting language maybe a better option from end-user configurability.

Ostensibly, what you are trying to do is build up an expression tree which can be used to check whether an item matches a particular predicate (i.e. is this item in a set?). For example item.colour == "Red" might expand to a tree that looks like this:

Equals {
  left: PropertyLookup {
    target: Variable {
      name: "item",
    property: "colour",
  right: StringLiteral("Red"),

And a DSL provides a concise way to build these sorts of expression trees. Given this is meant to be some sort of configuration file, you'll need to either use an existing scripting language or write one yourself.

Personally, I reckon Python would be a good fit for this sort of thing.

Python gives you the ability to hook into the property accessing machinery, so you could have the original item be a Variable object, and accessing a property (e.g. item.colour) returns a "query" which gets the colour property.

You can also do operator overloading so something that looks an equality check can actually return another of "query" object which represents the predicate item.colour == "Red". The way

I would also ask myself if it's worth going down this DSL path. Using a DSL gives you lots of expressiveness and power, but it'd also require a non-trivial amount of effort to implement, and needs some planning so you don't engineer yourself into a corner.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.