-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Question: namespace disambiguation rules #5234
Comments
Well, there are 2 The full details of how name resolution works is,.. well.. this monstrosity: flatbuffers/src/idl_parser.cpp Lines 1566 to 1617 in 407fb5d
In particular, here it looks thru all parents, based on the current name: flatbuffers/src/idl_parser.cpp Lines 1590 to 1595 in 407fb5d
This will cause it to first look for Foo.Bar.Bar.Person , then Foo.Bar.Person (which it finds), and then Bar.Person would have been next.
I believe that is similar to how C++ works? |
@aardappel Ah that makes sense, thanks for clarifying so promptly! :) |
@aardappel, Would you say that these two specs look correct? Just to make sure I'm understanding things correctly.
|
That looks correct to me :) You're making a Haskell implementation? How cool! Consider contributing it to the main repo when done. Why are you needing to figure out these namespaces though? You should let |
@aardappel Apologies for the late reply, I must have missed the notification from github 😮 Yes I am 😄 thank you! Yeah, I had to implement everything from scratch, as I wanted to use TemplateHaskell (TH) for codegen. TH has two big advantages:
The "downside" is that TemplateHaskell has to be written in, well, Haskell. I could theoritically call flatc to parse the schema file, do all the semantic validation, and then give me an AST, and then I'd use TemplateHaskell to turn the AST into Haskell code. The parsing wasn't that much trouble (~250 lines of mostly one-liners), the semantic validation step was the hard part (~800 lines)... I was under the impression that flatbuffers was more or less a stable project, so keeping these in sync would be ok-ish, but I'm starting to feel like that's not the case 😮 Is there a better channel to continue this conversation? gitter, maybe? |
That is cool.. in that way it makes sense for Haskell to be a standalone implementation, we can link to it from the FlatBuffers home page. I guess it is mostly stable at the moment, but the past has seen plenty of changes. I feel this is a better place for discussion than gitter, since this will be easier to find for people in the future :) |
@aardappel That sounds great, thank you! |
The main repo makes most sense if it is integrated with the main codegen and testing, like all the other languages there. Now haskell will have its own codegen, but still could share testing files etc. I'd be ok either way I think. Adding it to the main repo does have the expectation you'll stay involved in maintaining it, answering issues that relate to Haskell etc. |
Of course :) For now I think I'll focus on getting it to work, hopefully achieve feature parity with the official flatbuffers implementation (might take a while), and then we'll come back to this and decide where to host it :) |
I'm trying to understand how namespace resolution works.
From what I've tested so far:
In this case,
field: Bar.Y
could mean one of two things. It can be a reference to a typeY
in the nested namespaceFoo.Bar.Y
if it exists, otherwise it'll be a reference to a typeY
in the namespaceBar
.This behaviour seems normal to me. What surprised me was this:
Here, I expected
x: Bar.Person
to be a reference to the tablePerson
in the namespaceBar
.But it turns out, it's a reference to the struct in the namespace
Foo.Bar
.In fact, there seems to be no way to refer to the table in the namespace
Bar
.All of these things end up pointing to the struct:
Person
,Bar.Person
,Foo.Bar.Person
.The table seems to be completely shadowed by the struct, even though they're in different namespaces.
Is this the intended behaviour?
Where can I read more about these rules?
Flatc version: I'm using commit #8f8fb2b3677f55529f126f1adcc70b5dcdcd3290
The text was updated successfully, but these errors were encountered: