www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Variable Naming Issue (Conflicts?)

reply "Casey" <sybrandy gmail.com> writes:
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?
Apr 22 2014
next sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Casey:

 My question is, is there a way I can prevent this conflict from 
 occurring without affecting what the struct will look like?
prefix). Bye, bearophile
Apr 22 2014
parent reply "Casey" <sybrandy gmail.com> writes:
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?
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.
Apr 22 2014
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
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.
"$delete". Bye, bearophile
Apr 22 2014
parent "Casey" <sybrandy gmail.com> writes:

 "$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
Apr 22 2014
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
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
Apr 22 2014