-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add parsing of pointers #63
base: v2.x.x
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -965,3 +965,21 @@ ds: | |
catch (ConfigException exc) | ||
assert(exc.toString() == "/dev/null(1:11): es.enabled: Expected to be a value of type bool, but is a scalar"); | ||
} | ||
|
||
/// Test pointers | ||
unittest | ||
{ | ||
static struct N { | ||
@Optional int value; | ||
@Optional N* left, right; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think pointers should always be optional. I can't see a situation where they wouldn't be. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can think of one - when using mutually recursive types, only one point of recursion might be optional, e.g.: import configy.attributes;
/// Node for an AST for some language that uses infix operators.
struct Node {
// Only one of these must be set.
@Optional BinaryExpression* addition;
@Optional BinaryExpression* subtraction;
// ...
}
struct BinaryExpression {
// You've chosen which kind of expression this is.
// Now, you MUST specify the operands, so these are not optional:
Node* left, right;
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess |
||
} | ||
auto c = parseConfigString!N(`left: | ||
left: | ||
value: 1 | ||
right: | ||
value: 2 | ||
`, "/dev/null"); | ||
assert(c.left.left.value == 1); | ||
assert(c.left.right is null); | ||
assert(c.right.value == 2); | ||
} |
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.
That doesn't quite work for
const
/immutable
types though. A lot of the code in this module is convoluted to allow forconst
&immutable
values to be used.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.
Good catch. Fix pushed, not sure if that fix is the best way?