Parser doesn't support the & syntax
phated opened this issue · comments
I think this is a syntax for pointers but I can't find any documentation about it. It seems to be used when a struct is defined with a type that has yet-to-be-declared but that struct will point to the first struct, causing recursion. It also can be used to reference using the struct as a field property of itself.
Could you please give us some examples about this issue? I cannot understand what you are looking for.
@lujjjh This is the test fixture that the Thrift library uses for this feature:
struct RecTree {
1: list<RecTree> children
2: i16 item
}
struct RecList {
1: RecList & nextitem
3: i16 item
}
struct CoRec {
1: CoRec2 & other
}
struct CoRec2 {
1: CoRec other
}
struct VectorTest {
1: list<RecList> lister;
}
service TestService
{
RecTree echoTree(1:RecTree tree)
RecList echoList(1:RecList lst)
CoRec echoCoRec(1:CoRec item)
}
It seems that there is no such operator in Thrift IDL documentation. Also, there should not be any concepts like "pointer" in Thrift IDL. A pointer typically stores a memory address while Thrift is a communication protocol.
In fact, It is valid to refer to itself in a struct definition:
struct RecTree {
1: list<RecTree> children
2: i16 item
}
However, nextitem
in your RecList
struct must be optional
, or it may cause some problems since in theory, fields with default requiredness are always written.
struct RecList {
1: optional RecList nextitem
3: i16 item
}
@lujjjh the example I provided comes directly from the Thrift test suite, so it is something they support. You can find it in their tree at https://git-wip-us.apache.org/repos/asf?p=thrift.git;a=blob;f=test/Recursive.thrift;h=c9825821c4755b4a0e82700368717d33494d0934;hb=HEAD
It might be undocumented in the IDL like many of the C/C++ specific pieces (which I think this is?).
Oh okay. But the parser should still parse it and present it to the compiler in some way, right?