catala icon indicating copy to clipboard operation
catala copied to clipboard

An attribute language for Catala code items

Open denismerigoux opened this issue 2 years ago • 1 comments
trafficstars

The problem

While discussing #293, we were wondering whether we should add new syntax to Catala to be able to express the date rounding mode. In this case, the result was yes because we deemed it significant enough. However, there will be many cases when we want to attach information to a point of the code (a scope, a variable, a definition, etc.).

One use case for such additional information might be for a custom Catala backend that translates Catala programs to specific language in a specific legacy environment where the new Catala program connects to an older application. You might want to specify at the level of a scope signature which variables of the Catala scope connect to which variables of a function in the legacy application.

An example of a fully-fledged attribute language is the one of Rust.

Discussion

By designing and implementing a fully-fledged attribute language ahead, we are future-proof and offer a flexible system for custom needs in attaching information to the AST. As for Rust, this could be used for storing comments and documentation in the AST.

But by offering such a mechanism, we are allowing users to clutter the code with metadata that is not related to the text of the law. The syntax of the attribute language might also confuse lawyers and obscure their ability to read the codebase.

A compromise could be to still design this attribute language, but implement it in an extrinsic way. Instead of putting the attributes directly in the source code, you could have an external .metadata file containing the association of attributes to code items :

TaxModule.IncomeTaxScope.some_var : attribute1, attribute2, etc.

The compiler should statically check whether the items referenced in the metadata file exist and attach the info at the AST level.

What do you think?

denismerigoux avatar Feb 13 '23 15:02 denismerigoux

I need to examinate the options more thoroughly, but I would tend to prefer inline attributes, which are generally easier to maintain.

Another use I'd be very happy about could be attaching labels and specifications to the user-directed inputs, to help generate forms ot interactive applications.

AltGr avatar Feb 22 '23 11:02 AltGr

Closed because it's implemented now!

denismerigoux avatar Jul 29 '25 08:07 denismerigoux