Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Parsing for optional complex classes fails #521

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

Parsing for optional complex classes fails #521

jeromesimeon opened this issue Mar 13, 2020 · 3 comments
Labels
0.21 Type: Bug 🐛 Something isn't working

Comments

@jeromesimeon
Copy link
Member

The current optional parsing does not work for missing optional complex types.

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.

@jeromesimeon jeromesimeon added the Type: Bug 🐛 Something isn't working label Mar 13, 2020
@martinhalford
Copy link
Member

martinhalford commented Mar 14, 2020

Just for completeness, the error also occurs for the optional simple types too, not just complex types.

For example, if you do the following:

  1. Download the LateDeliveryAndPenaltyContract from the Accord Template Library,
  2. Add optional to the o Duration penaltyDuration optional in the asset LateDeliveryAndPenaltyContract within model.cto, and then
  3. Remove the penaltyDuration from the sample.md (e.g. ""Dan" (the Seller) shall pay to "Steve" (the Buyer) for every days of delay penalty" <-- notice integer missing between "every" and "days")
  4. Then execute cicero parse --template ./ --sample ./text/sample.md, the following error occurs:
error: Type error (at file logic/logic.ergo line 37 col 40). Function `org.accordproject.time.durationAs' expected argument `du' to be of type `Duration' but was given argument of type `Duration?'.

@martinhalford
Copy link
Member

Similarly, if you do the following:

  1. Add the o String DummyText to the asset LateDeliveryAndPenaltyContract within model.cto, and then,
  2. Add {{DummyText}} somewhere in the grammar.tem.md, and then
  3. Add "Some dummy text" somewhere in the sample.md, and then
  4. Execute cicero parse --template ./ --sample ./text/sample.md, and then
  5. All good! :-)
  6. Now delete the "Some dummy text" (including " quotes) from sample.md
  7. Re-run cicero parse --template ./ --sample ./text/sample.md,
  8. Get the following error:
error: invalid syntax at line 4 col 1:

  In case of delayed delivery except for Force Majeure cases,
  ^
Unexpected "I"

Parse errors at next character after expected {{DummyText}} variable.

@jeromesimeon
Copy link
Member Author

This problem does not appear fixed in the latest release of Cicero, version 0.21.0... I'm investigating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.21 Type: Bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants