digitalmars.D.learn - legal identifier check
- Saaa (1/1) May 30 2009 Is there a function to check whether some string is a legal identifier?
- downs (3/6) May 30 2009 Sure.
- Saaa (14/21) May 31 2009 That is a compile time check, right?
- Daniel Keep (2/13) May 31 2009 That's not correct. http://digitalmars.com/d/1.0/lex.html#identifier
- Saaa (3/13) May 31 2009 Which is why I asked for it here :)
- BCS (3/7) May 31 2009 that checks to see if the {...} is a valid delegate literal by using is(...
- Saaa (1/8) May 31 2009 Ah, I see. Can this be done at runtime?
- grauzone (3/14) May 31 2009 You have to write it yourself. Here's a good starting point:
- Saaa (6/8) May 31 2009 Yes, that was my starting point and it seemed quite complex, thus my
- BCS (2/12) May 31 2009 if you are only working with ASCII: use the regex `_A-Za-z[_A-Za-z0-9]*`
- Saaa (1/2) May 31 2009 Is that better than the inPattern way?
- BCS (2/7) May 31 2009 yes, it correctly rejects numbers at the start and should be faster as w...
- Saaa (1/9) May 31 2009 Of course, should have looked longer at the regex line, thanks!
- Robert Fraser (2/16) May 31 2009 Isn't there an isUniAlpha function in both Phoboses and in Tango?
- =?ISO-8859-1?Q?=22J=E9r=F4me_M=2E_Berger=22?= (8/23) Jun 01 2009 Shouldn't that be "[_A-Za-z][_A-Za-z0-9]*"?
- BCS (2/23) Jun 01 2009 Oops :(
Is there a function to check whether some string is a legal identifier?
May 30 2009
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 */ }))) ...
May 30 2009
Saaa wrote: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; } }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 */ }))) ...
May 31 2009
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
May 31 2009
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.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
May 31 2009
Hello Saaa,that checks to see if the {...} is a valid delegate literal by using is() to see if semantic checks fail.static if(is(typeof({ /* code to be checked for validity goes here */ }))) ...How does that piece of code work anyways :D
May 31 2009
Hello Saaa,Ah, I see. Can this be done at runtime?that checks to see if the {...} is a valid delegate literal by using is() to see if semantic checks fail.static if(is(typeof({ /* code to be checked for validity goes here */ }))) ...How does that piece of code work anyways :D
May 31 2009
Saaa wrote:You have to write it yourself. Here's a good starting point: http://www.digitalmars.com/d/1.0/lex.html#identifierHello Saaa,Ah, I see. Can this be done at runtime?that checks to see if the {...} is a valid delegate literal by using is() to see if semantic checks fail.static if(is(typeof({ /* code to be checked for validity goes here */ }))) ...How does that piece of code work anyways :D
May 31 2009
You have to write it yourself. Here's a good starting point: http://www.digitalmars.com/d/1.0/lex.html#identifierYes, 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.
May 31 2009
Hello Saaa,if you are only working with ASCII: use the regex `_A-Za-z[_A-Za-z0-9]*`You have to write it yourself. Here's a good starting point: http://www.digitalmars.com/d/1.0/lex.html#identifierYes, 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.
May 31 2009
if you are only working with ASCII: use the regex `_A-Za-z[_A-Za-z0-9]*`Is that better than the inPattern way?
May 31 2009
Hello Saaa,yes, it correctly rejects numbers at the start and should be faster as well.if you are only working with ASCII: use the regex `_A-Za-z[_A-Za-z0-9]*`Is that better than the inPattern way?
May 31 2009
Hello Saaa,Of course, should have looked longer at the regex line, thanks!yes, it correctly rejects numbers at the start and should be faster as well.if you are only working with ASCII: use the regex `_A-Za-z[_A-Za-z0-9]*`Is that better than the inPattern way?
May 31 2009
BCS wrote:Hello Saaa,Isn't there an isUniAlpha function in both Phoboses and in Tango?if you are only working with ASCII: use the regex `_A-Za-z[_A-Za-z0-9]*`You have to write it yourself. Here's a good starting point: http://www.digitalmars.com/d/1.0/lex.html#identifierYes, 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.
May 31 2009
BCS wrote:Hello Saaa, =20`=20 if you are only working with ASCII: use the regex `_A-Za-z[_A-Za-z0-9]*=You have to write it yourself. Here's a good starting point: http://www.digitalmars.com/d/1.0/lex.html#identifierYes, 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.=20Shouldn't that be "[_A-Za-z][_A-Za-z0-9]*"? Jerome --=20 mailto:jeberger free.fr http://jeberger.free.fr Jabber: jeberger jabber.fr
Jun 01 2009
Reply to Jérôme,BCS wrote:Oops :(Hello Saaa,Shouldn't that be "[_A-Za-z][_A-Za-z0-9]*"? Jeromeif you are only working with ASCII: use the regex `_A-Za-z[_A-Za-z0-9]*`You have to write it yourself. Here's a good starting point: http://www.digitalmars.com/d/1.0/lex.html#identifierYes, 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.
Jun 01 2009