accordproject / template-archive

Smart Legal Contracts & Templating System
https://accordproject.org/projects/cicero/
Apache License 2.0
282 stars 119 forks source link

Flexible & Modular Parsing/Drafting for Cicero templates #553

Open jeromesimeon opened 4 years ago

jeromesimeon commented 4 years ago

Is your feature request related to a problem? Please describe.

It is currently difficult to create custom text in clauses or contracts for specific types (e.g., for addresses, amounts, stock quotes).

Specific contracts / data may need specific rendering or text representation, but currently those have to be built into Cicero which limits a users's ability to specialize the text for their unique needs.

Describe the solution you'd like

It would be wonderful if users could easily specify special purpose parsing/drafting code for specific types.

jeromesimeon commented 4 years ago

The new parser work (in markdown-transform) includes a minimal kind of parsing table which could be a start in supporting more modular parsing/drafting.

Some notes from discussion with @dselman on the topic:

Parser Manager

dselman commented 4 years ago

Very nice.

I think I lean towards making the loading of remote grammars a separate concern, so that we don't have network access inside the ParserManager. E.g. we could create another class that takes a map of CTO FQN -> URL and resolves it to CTO FQN -> Grammar.

We can then decide how this gets exposed inside a Cicero archive. E.g. something like:

type-grammars.json inside the text directory.

[
   {
      "fqn" : "org.acme.Address",
      "locale" : "en-GB",
      "url" : "https://acme.org/templates/address.tem.md"
   },
   {
      "fqn" : "org.acme.Person",
      "locale" : "en",
      "grammar" : "{{salutation}} {{lastName}} {{firstName}}"
   }
]

Or sub-folders, if we wanted to make it easier to edit (no problems escaping quotes, for example):

/text/org.acme.Address/en-GB/ref.json (definition packaged outside the template, JSON contains the URL) /text/org.acme.Person/en/grammar.tem.md (definition packaged inside the template)