-
Notifications
You must be signed in to change notification settings - Fork 161
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
X3: Remove single element tuple attributes special handling #463
Comments
Would such type struct number {
double value;
number& operator=(double x) { value = x; return *this; }
}; work when inherited from |
It should. Why not to try yourself before asking? |
In case of potential bugs - recently I have experienced enough bugs with Spirit that I better verify whether what I do is correct use of the library or not (to confirm whether the error comes from my misuse or from library bug). |
What do you think about adding static assert for 1-element fusions? |
I do not know what you mean by that. Quoting myself (from the first post):
|
I mean placing a static assert that checks if a rule is instantiated using 1-element fusion. If so, make a compile error and mention to overload |
The rule should not do such a thing. Moreover, you can add a custom parser that will handle any type you want, |
Then I propose a tutorial page in the doc that will explain how to write a custom parser (some example boilerplate code and where to put what) |
I'm with @Xeverous on this. It would be really nice to have a clear error message; the current error
(code from: #574 (comment)) If it's going to be treated as an error anyway, why not show a simple message by static_assert? |
I would love to get a PR :-) |
Assert straight at the beginning? Or "the beginning (function)" is already reused by recursion which causes problems in cases assert should not fire? Btw I think X3 should document some recommendations for making AST types in its tutorial as what I'm currently following is a result of trial-and-error: When making an AST type, I'm always going into 1 of these:
Other mixes of AST types end in various (long long) compilation errors. |
@Xeverous your examples are really useful IMHO. I wish I had known that three years ago. I personally have never inherited from |
I actually don't remember who/where told me about inheriting from containers and My X3-based project has a lot of grammars (60+) so you might want to check https://github.com/Xeverous/filter_spirit/tree/develop/src/lib/fs/parser how exactly I use X3. |
You are very welcome to propose improvements to documentation via opening a pull request. The problem is that people do not read the documentation |
The variant example is mentioned but:
|
I am sorry, but you did not mention it and said just above that the documentation should have it.
Fusion sequences are supported as sequences for sequence parser and as values for any other parser. It just happens that sequence parser is documented as
to not produce single element tuple and there is no (or prove me wrong) mention that value parser will treat
I am not sure I understand you. Spirit (non-container/variant value parser) uses
There are many ways to design your AST, what is working for you may not work for others.
You can share your experience via a blog post or documentation update pull request. |
There are actually two fixes: the first one is a direct fix to the linked issue. The attribute of the rule for switch was wrong. I'm not sure how I missed that, but OK, now we have tests. The other bug: For some reason, the completion generator prevented the symbol table parser from running and the value inside the resulting switch_ was undefined. Asserting the attribute of the completion generator seems to solve the issue. I thought this would have something to do with the fact that I'm using single member fusion structs. However, the bug still persisted even when converting them into non-fusion structs (as suggested in the first issue). At some point, all single-member fusion structs should be converted into non-fusion structs, but because it doesn't solve my problem, I won't be doing it now. Issue: boostorg/spirit#463 Issue: boostorg/spirit#659 Issue: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/218 Change-Id: I364b32b76741c198808cc2b3c5027913162d0703
The question about single element tuple attributes arises from time to time. We have some basic support for unwrapping them and because of that users use them and find that more complex situation are not supported.
Usually I think that what's logical for users that should be supported and previously I implemented some logic to improve the handling, but with time I realized that it the basics of this usage is ill-formed, because such attributes are simultaneously could be of plain, container and Fusion sequences types.
There also no benefits in using them, most frequently the question arises in term of adapted Fusion structs:
or
There is no reason to use them instead of:
No Fusion, supported already, clear logic. If someone do not like inheritance in the case above they could provide STL container API for their class, or specialize the traits.
By removing special handling of single element sequence I mean removing of currently supported:
It will allow to place a static assertion in
parse_into_container
that expectstraits::is_container
to be true for the attribute.Refs: #178 #408 #461
The text was updated successfully, but these errors were encountered: