Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Should CiceroMark Support optional variables? #520

Open
jeromesimeon opened this issue Mar 13, 2020 · 6 comments
Open

Should CiceroMark Support optional variables? #520

jeromesimeon opened this issue Mar 13, 2020 · 6 comments

Comments

@jeromesimeon
Copy link
Member

jeromesimeon commented Mar 13, 2020

From @martinhalford

Support for "optional" in Concerto

The Concerto modeling language supports optional properties in types, which is great, as sometimes not all parameters in an agreement are mandatory.

At the moment, if a property is designated as optional then the Cicero parser ignore it. An error is then thrown claiming that the property is missing.

It would be great if Cicero parser could support optional properties in Concerto.

model_cto_—_helloworld-person-1

model_cto_—_helloworld-person-2

@dselman
Copy link
Contributor

dselman commented Mar 13, 2020

This sounds like a regression. I'm pretty sure the parser generator used to handle optionals:
https://github.com/accordproject/cicero/blob/master/packages/cicero-core/src/grammarvisitor.js#L198

@jeromesimeon
Copy link
Member Author

This sounds like a regression. I'm pretty sure the parser generator used to handle optionals:
https://github.com/accordproject/cicero/blob/master/packages/cicero-core/src/grammarvisitor.js#L198

This isn't related to parsing for optional, only the constraints for the new {{#with}}...{{/with}} block.

The current parsing/drafting for optional values should work but will not allow for custom text for those variables.

The way I understand the issue is the ability to write something like:

{{#optional address}}
This customer lives at {{streetName}}, {{zipCode}} in {{city}}
{{else}}
This customer does not have a home address.
{{/optional}}

@jeromesimeon
Copy link
Member Author

jeromesimeon commented Mar 13, 2020

The current optional parsing works, but I am getting another kind of error (which may be a regression, I'm actually unsure).

For the model:

/**
 * The template model
 */
concept Address {
   o String zipCode
   o String streetName
   o String city
}

asset AcceptanceOfDeliveryClause extends AccordClause {
   o Address address optional
  /**
   * the shipper of the goods
   */
   --> Organization shipper
...

And the template:

Customer lives at:{{address}}

## Acceptance of Delivery.

{{shipper}} will be deemed to have completed its delivery obligations
if in {{receiver}}'s opinion, the {{deliverable}} satisfies the
Acceptance Criteria, and {{receiver}} notifies {{shipper}} in writing
that it is accepting the {{deliverable}}.
...

And the sample.md text:

Customer lives at:"MainStreet" "10000" "New York"

## Acceptance of Delivery.

"Party A" will be deemed to have completed its delivery obligations
if in "Party B"'s opinion, the "Widgets" satisfies the
Acceptance Criteria, and "Party B" notifies "Party A" in writing
that it is accepting the "Widgets".
...

It parses correctly:

bash-3.2$ cicero parse --sample text/sample.md
cicero parse --sample text/sample.md
11:42:01 AM - info: Using current directory as template folder
11:42:03 AM - info:
{
  "$class": "org.accordproject.acceptanceofdelivery.AcceptanceOfDeliveryClause",
  "clauseId": "5beda0c6-a1cc-4f05-9cd0-529e57b9a50a",
  "address": {
    "$class": "org.accordproject.acceptanceofdelivery.Address",
    "zipCode": "MainStreet",
    "streetName": "10000",
    "city": "New York"
  },
  "shipper": "Party A",
  "receiver": "Party B",
  "deliverable": "Widgets",
  "businessDays": 10,
  "attachment": "Attachment X"
}

But for an empty address:

Customer lives at:

## Acceptance of Delivery.

"Party A" will be deemed to have completed its delivery obligations
if in "Party B"'s opinion, the "Widgets" satisfies the
Acceptance Criteria, and "Party B" notifies "Party A" in writing
that it is accepting the "Widgets".
...

I get:

bash-3.2$ cicero parse --sample text/sample-noaddress.md
cicero parse --sample text/sample-noaddress.md
11:42:06 AM - info: Using current directory as template folder
11:42:08 AM - error: Cannot read property '$class' of null

This should be filed as a separate bug I think.

@martinhalford
Copy link
Member

Hi Jerome, I think this bug occurs for simple types too - like String. I have added some comments to #521 with steps to reproduce.

@dselman
Copy link
Contributor

dselman commented Mar 14, 2020

In this example did you make DummyText optional?

@martinhalford
Copy link
Member

Hi @dselman,
Yes, the DummyText was optional.

 o String DummyText optional

See details in #521
See also attached, .CTA (as .ZIP archive)

ldp-optional-dummy-text.zip

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants