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

Code generation from ast.ts/djot-schema.json #235

Open
bdarcus opened this issue Jul 20, 2023 · 3 comments
Open

Code generation from ast.ts/djot-schema.json #235

bdarcus opened this issue Jul 20, 2023 · 3 comments

Comments

@bdarcus
Copy link

bdarcus commented Jul 20, 2023

A couple of us have been looking into automatically-generating Rust AST code from the definitions here. We tried three different converters, but none of them provides any results.

hellux/jotdown#17 (comment)

Here's what I get with quicktype from the json schema, but the same error with the typescript:

quicktype -s schema  -l rs -t Doc djot-schema.json
Error: Maximum call stack size exceeded.quicktype -s ts  -l rs -t Doc src/ast.ts
Error: Maximum call stack size exceeded.

Which makes me wonder if there's something about the typescript definition, and/or the json schema conversion, that is causing these problems?

@clbarnes
Copy link

The result of my effort with typify: oxidecomputer/typify#269

@jgm
Copy link
Owner

jgm commented Jul 20, 2023

No idea. @matklad may have more insight.

@bdarcus
Copy link
Author

bdarcus commented Jul 20, 2023

Preface: maybe I should have added this to the js repo instead? Feel free to move it of course.

In looking at the generated schema, I'm not sure all of it matches the source.

For example, here's a schema definition:

        "Record<string,Footnote>": {
            "additionalProperties": false,
            "type": "object"
        },

And here's the source (I think):

  footnotes: Record<string, Footnote>;

It looks to me like the TS is tighter than the schema.

I ran into these sorts of issues when testing these tools; one of the reasons I switched to Rust (I'm using schemars to generate the schemas; that works very well).

EDIT: basically, I don't think you can rely on automatic schema generation in JS/Typescript; the schema will not match the code precisely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants