Re: legal identifier check

2009-06-01 Thread Jérôme M. Berger

BCS wrote:

Hello Saaa,


You have to write it yourself. Here's a good starting point:
http://www.digitalmars.com/d/1.0/lex.html#identifier


Yes, that was my starting point and it seemed quite complex, thus my
question :)
I think I'll stay with my simple check for now as it isn't really
necessary
to be as strict as D's identifiers.
Just thought that if there was an easy check I'd implement that.
Thanks anyways everybody.


if you are only working with ASCII: use the regex `_A-Za-z[_A-Za-z0-9]*`


Shouldn't that be [_A-Za-z][_A-Za-z0-9]*?

Jerome
--
mailto:jeber...@free.fr
http://jeberger.free.fr
Jabber: jeber...@jabber.fr



signature.asc
Description: OpenPGP digital signature


Re: legal identifier check

2009-06-01 Thread BCS

Reply to Jérôme,


BCS wrote:


Hello Saaa,


You have to write it yourself. Here's a good starting point:
http://www.digitalmars.com/d/1.0/lex.html#identifier


Yes, that was my starting point and it seemed quite complex, thus my
question :)
I think I'll stay with my simple check for now as it isn't really
necessary
to be as strict as D's identifiers.
Just thought that if there was an easy check I'd implement that.
Thanks anyways everybody.

if you are only working with ASCII: use the regex
`_A-Za-z[_A-Za-z0-9]*`


Shouldn't that be [_A-Za-z][_A-Za-z0-9]*?

Jerome



Oops :(




Re: legal identifier check

2009-05-31 Thread Saaa
 Saaa wrote:
 Is there a function to check whether some string is a legal identifier?



 Sure.

 static if(is(typeof({ /* code to be checked for validity goes here */ }))) 
 ...

That is a compile time check, right?
I meant a runtime check.

How does that piece of code work anyways :D
static if = compile time if
is = comparison between two non value things?
typeof = returns the type

I know use this (in the ddata thread above):

foreach(char c; identifier)
{
 if( !inPattern( c, `_a-zA-Z0-9`) )
 {
  return false;
 }
} 




Re: legal identifier check

2009-05-31 Thread Daniel Keep


Saaa wrote:
 ...
 
 I know use this (in the ddata thread above):
 
 foreach(char c; identifier)
 {
  if( !inPattern( c, `_a-zA-Z0-9`) )
  {
   return false;
  }
 } 

That's not correct.  http://digitalmars.com/d/1.0/lex.html#identifier


Re: legal identifier check

2009-05-31 Thread BCS

Hello Saaa,


static if(is(typeof({ /* code to be checked for validity goes here */
}))) ...


How does that piece of code work anyways :D



that checks to see if the {...} is a valid delegate literal by using is() 
to see if semantic checks fail.





Re: legal identifier check

2009-05-31 Thread Saaa
 I know use this (in the ddata thread above):

 foreach(char c; identifier)
 {
  if( !inPattern( c, `_a-zA-Z0-9`) )
  {
   return false;
  }
 }

 That's not correct.  http://digitalmars.com/d/1.0/lex.html#identifier
Which is why I asked for it here :)
It isn't extremely important as it is just a data format, but I would like 
to be as D as possible. 




Re: legal identifier check

2009-05-31 Thread Saaa

 Hello Saaa,

 static if(is(typeof({ /* code to be checked for validity goes here */
 }))) ...

 How does that piece of code work anyways :D


 that checks to see if the {...} is a valid delegate literal by using is() 
 to see if semantic checks fail.

Ah, I see. Can this be done at runtime? 




Re: legal identifier check

2009-05-31 Thread grauzone

Saaa wrote:

Hello Saaa,


static if(is(typeof({ /* code to be checked for validity goes here */
}))) ...


How does that piece of code work anyways :D


that checks to see if the {...} is a valid delegate literal by using is() 
to see if semantic checks fail.


Ah, I see. Can this be done at runtime? 



You have to write it yourself. Here's a good starting point:
http://www.digitalmars.com/d/1.0/lex.html#identifier


Re: legal identifier check

2009-05-31 Thread Saaa


 You have to write it yourself. Here's a good starting point:
 http://www.digitalmars.com/d/1.0/lex.html#identifier

Yes, that was my starting point and it seemed quite complex, thus my 
question :)
I think I'll stay with my simple check for now as it isn't really necessary 
to be as strict as D's identifiers.
Just thought that if there was an easy check I'd implement that.
Thanks anyways everybody. 




Re: legal identifier check

2009-05-31 Thread Saaa
 Hello Saaa,

 if you are only working with ASCII: use the regex
 `_A-Za-z[_A-Za-z0-9]*`

 Is that better than the inPattern way?


 yes, it correctly rejects numbers at the start and should be faster as 
 well.

Of course, should have looked longer at the regex line, thanks! 




Re: legal identifier check

2009-05-31 Thread Robert Fraser

BCS wrote:

Hello Saaa,


You have to write it yourself. Here's a good starting point:
http://www.digitalmars.com/d/1.0/lex.html#identifier


Yes, that was my starting point and it seemed quite complex, thus my
question :)
I think I'll stay with my simple check for now as it isn't really
necessary
to be as strict as D's identifiers.
Just thought that if there was an easy check I'd implement that.
Thanks anyways everybody.


if you are only working with ASCII: use the regex `_A-Za-z[_A-Za-z0-9]*`


Isn't there an isUniAlpha function in both Phoboses and in Tango?


legal identifier check

2009-05-30 Thread Saaa
Is there a function to check whether some string is a legal identifier? 




Re: legal identifier check

2009-05-30 Thread downs
Saaa wrote:
 Is there a function to check whether some string is a legal identifier? 
 
 

Sure.

static if(is(typeof({ /* code to be checked for validity goes here */ }))) ...