lutaml / expressir

Ruby parser for the ISO EXPRESS language
3 stars 2 forks source link

Generalise sourcecode to all elements of expressir #45

Closed opoudjis closed 3 years ago

opoudjis commented 3 years ago

So far, my understanding is, sourcecode has been realised only for schema and entity so far.

However, the intention for metanorma is that the entire sourcecode of express needs to be replicated in a document. That means that functions, and indeed all elements of express need to have their sourcecode made available, just as they need to have their remarks made available as documentation.

cc @w00lf : @w00lf will need to serialise all such sourcecode attributes.

zakjan commented 3 years ago

After chatting with @w00lf and @opoudjis , I implemented keeping the original source code on all identifiable nodes. We'll see if it works well for the use case.

@ronaldtse This also solves the issue with untagged remarks, they are going to be available in the original source code. I know that in the beginning I thought this is not doable with ANTLR4, but fortunately later I found a way.

Other alternatives such as adding formatted source code on the nodes (as a static attribute, or a getter) have the issue that they tie the model classes to the one particular formatter implementation.

ronaldtse commented 3 years ago

@zakjan the solution seems perfect. Thanks! We can always have two methods, the 'original source code' (which is stored) and the 're-formatted source code' (which is recursively generated dynamically), to satisfy the needs.

zakjan commented 3 years ago

Thanks, merging.

If multiple different export formats are still the case, for passing re-formatted source code to Liquid templates we might need to implement calling the formatter(s) somewhere else in the chain, so that the model classes can stay decoupled on the formatter(s).

A custom Liquid filter called like {{ entity | exp }} would be one of the options, but based on @w00lf's findings, it is not easily possible to pass a custom object to the template. Guessing from https://github.com/Shopify/liquid/blob/master/lib/liquid/extensions.rb it seems to me it might be possible to whitelist custom objects somehow.

ronaldtse commented 3 years ago

for passing re-formatted source code to Liquid templates we might need to implement calling the formatter(s) somewhere else in the chain, so that the model classes can stay decoupled on the formatter(s).

External access such as a Liquid filter can exist in lutaml-express instead of Expressir. The approach of {{ entity | express_method }} could work.