Re: [Pyparsing] How to distinguish a variable from a integer
Brought to you by:
ptmcg
From: Gustavo N. <me...@gu...> - 2009-05-14 18:04:16
|
Bonjour, Denis. spir said: > The issue is that your variables can start like a number (the reason why in > most PLs var names cannot start with a digit). So that: * using (number | > variable) number masks variable > * using the opposite number is eaten by variable > > You should use the common pattern for a variable, requiring letter or '_' > at start: variable = Regex("[a-zA-Z_]\w*", re.UNICODE) (untested with > unicode) Yes, I was aware of that limitation with regular expressions, but I thought there was a way to work around that with Pyparsing. >(also beware that \w includes digits and '_') Oops, you're right. Thanks! > so that number and variable are mutually exclusive. > > You could also add a lookahead for !(letter | '_') trailing after the > definition of number, but then your definition of variable is unclear. It > should be required that a variable has at least one non-digit char. Which > is uneasy ;-) Yep, that's not a good solution either. Well, I'll have to make sure variables don't start with a number. :/ Merci beaucoup! -- Gustavo Narea <xri://=Gustavo>. | Tech blog: =Gustavo/(+blog)/tech ~ About me: =Gustavo/about | |