migamake / json-autotype

Automatic Haskell type inference from JSON input
149 stars 23 forks source link

Correct escaping for reserved keywords #35

Closed sigrlami closed 5 years ago

sigrlami commented 5 years ago

This is solution for the issue 31 related to the missing TopLevel construct. If user adds argument -t Blah it's prefixed correctly and issue not visible.

In provided example, after close examination of example reddit.json json file and making multiple test runs

{
  "kind": "Listing",
  "data": {
    "modhash": "",
    "dist": 26,
    "children": [
      {
        "kind": "t3",
        "data": {
          "approved_at_utc": null,
          "subreddit": "haskell",
          ...
        }
      }
    ],
    "after": "t3_cr80iz",
    "before": null
  }
}

I found that escaping Haskell keywords not full. More over it's not applied for the field declarations which led to several errors that avoided building TopLevel declaration. Notice kind keyword inside children array.

This fix adds