Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
April 22, 2014 Variable Naming Issue (Conflicts?) | ||||
---|---|---|---|---|
| ||||
Hello, I'm working on some code where I'm trying to generate structs that map to JSON documents via a mixin. That part works except when specific variable gets created. Below is the error that I'm getting: source/objects.d-mixin-70(75): Error: no identifier for declarator string source/objects.d-mixin-70(75): Error: found '=' when expecting '(' source/objects.d-mixin-70(75): Error: basic type expected, not "" source/objects.d-mixin-70(75): Error: found '""' when expecting ')' If I prefix all of the generated variables with an underscore, it works fine. It looks like the variable "delete" is the issue. To me, it looks like it's expecting some sort of "delete" method. Now, I'm planning on leveraging vibe.d's JSON serialization to convert an object to/from JSON, so the variable names have to match the names they have in the JSON document. My question is, is there a way I can prevent this conflict from occurring without affecting what the struct will look like? |
April 22, 2014 Re: Variable Naming Issue (Conflicts?) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Casey | Casey:
> My question is, is there a way I can prevent this conflict from occurring without affecting what the struct will look like?
The usual strategy is to append an underscore. (I think C# uses a @ prefix).
Bye,
bearophile
|
April 22, 2014 Re: Variable Naming Issue (Conflicts?) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Casey | On Tue, 22 Apr 2014 15:35:33 -0400, Casey <sybrandy@gmail.com> wrote:
> If I prefix all of the generated variables with an underscore, it works fine. It looks like the variable "delete" is the issue. To me, it looks like it's expecting some sort of "delete" method.
delete is a keyword, it cannot be a symbol.
-Steve
|
April 22, 2014 Re: Variable Naming Issue (Conflicts?) | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Tuesday, 22 April 2014 at 19:38:09 UTC, bearophile wrote:
> Casey:
>
>> My question is, is there a way I can prevent this conflict from occurring without affecting what the struct will look like?
>
> The usual strategy is to append an underscore. (I think C# uses a @ prefix).
>
> Bye,
> bearophile
I've done that, but then it changes the name which, from what I've read in the documentation, means the JSON -> object conversion won't work since it won't see a variable named delete.
|
April 22, 2014 Re: Variable Naming Issue (Conflicts?) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Casey | Casey:
> I've done that, but then it changes the name which, from what I've read in the documentation, means the JSON -> object conversion won't work since it won't see a variable named delete.
Perhaps we need a built-in syntax solution as in C#, like a "$delete".
Bye,
bearophile
|
April 22, 2014 Re: Variable Naming Issue (Conflicts?) | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | > Perhaps we need a built-in syntax solution as in C#, like a "$delete".
So, two things:
1. I guess my current approach is screwed. I figured as much.
2. Seeing "$delete" makes me miss Perl/PHP variable naming. It is one extra character, but it did make them stand out more.
Anyway, thanks.
Casey
|
Copyright © 1999-2021 by the D Language Foundation