-
Notifications
You must be signed in to change notification settings - Fork 50
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
schema/dmt: first pass at a parser #253
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My skim of the parser has been fairly fast, but it looks like a parser, and it looks like it has quite good error handling (line and offsets, etc) as a bonus... and if it parses the schema-schema, that is indeed quite a bunch of practical exercise and test already. Amazing!
It looks like we don't test that the parser of the schema-schema DSL is functionally equivalent to the schema-schema JSON load, yet? Is it time to test that? It might be as easy as feeding to the two of them to the |
That sounds like a good idea. I'd probably say that's second PR territory, because it's likely going to find a few more bugs, and this PR is big enough as it is :) |
SGTM. My thumb is up! |
Waiting on ipld/ipld#137 (comment) to get a decision. |
I would probably move the whole Parse function family to another package. |
I don't have a strong opinion on the names of schema vs DMT vs DSL, but I do think we should avoid adding more packages into the mix. go-ipld-prime already has dozens of packages, and I fear that adding more packages and placing the high-level APIs there will just further confuse the new users. If you're worried about getting confused by the fully qualified name |
I'm not so worried about more packages. Worried about undiscoverability if high-level APIs end up hidden in deeply nested packages: yes. But we already have that problem with The solution to discoverability issues for this stuff seems to me to usually shake out to making a top-level package that just focuses purely on the discoverability concern. To pursue that: one option would be to make an
|
Oh, I like that. I had been thinking about what to name a "parse and compile schema" API, and where to put it. Now it seems clear it should go in the root package. If anyone wants something more specific, such as parsing the DSL but keeping it in DMT non-compiled form, then they could drop down to one of the sub-packages. |
Yep. And the root (A little more backstory: The |
I still don't have a strong opinion on whether to split DSL from DMT. You're right that they could be split, and they sit in different levels. On the other hand, the new DMT package will have a very small API, and I'm not a fan of splitting a package with a small API into two packages with even smaller APIs. They would both be relatively small amounts of code, too. I think I lean slightly towards splitting the packages, if anything because To get to the tip of the bikeshedding: most end users will want to go from a schema file to a compiled Schema they can use with e.g. bindnode. So they really want a "Parse and Compile" API. But I really don't like
My intuition is that we should probably not pull that trick more than once in this module. The existing codebase has enough packages and dependency tree magic as it is :) |
Plenty of TODOs scattered around, but it's complete enough that it can parse the schema-schema. We include ParseBytes for the upcoming go:embed usecases, and ParseFile for the common non-embed usecase. The parser is largely inspired by github.com/ipld/go-ipld-schema/parser, with some notable differences. First, it follows a top-down recursive descent design, with methods such as "consume token" and "peek token". This also enables us to provide consistently good errors. Second, it's not line-based, using bufio.Reader instead. This keeps the code simpler, as we aren't forced to tokenize by line, and we also avoid potential mistakes when slicing tokens by hand. Third, it parses straight into the new bindnode DMT types, which allows for Parse and Compile to be chained together. Note that the parser lives in schema/dsl, which sits on top of schema/dmt with the Go types and schema definition. This is a nice separation at a conceptual level, and also means one can use the DMT without pulling in the DSL parser. Finally, we bump the ipld submodule to get Eric's schema-schema changes that mean implicit scalar values are no longer quoted in the DSL. Updates #188.
Moved the Parse API with its test to schema/dsl. Following schema/dmt being named schemadmt, the package is called schemadsl. Note that Compile remains in schemadmt. That seems like the right place to me: it has nothing to do with the DSL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks even better than ever -- let's merge it!
(see commit message)