Hi Paul, <br>
<br>
My apologies, as I was jumping into my car after sending that email, it clicked in my brain. <br>
&quot;Oh yeah... initial &amp; body...&quot;<br>
<br>
But good to know about how to accept valid numbers.<br>
<br>
Sorry, getting a bit too quick to fire off emails here.<br>
<br>
Regards, <br>
<br>
Liam Clarke<br><br><div><span class="gmail_quote">On 7/25/05, <b class="gmail_sendername">Paul McGuire</b> &lt;<a href="mailto:paul@alanweberassociates.com">paul@alanweberassociates.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Liam -<br><br>The two arguments to Word work this way:<br>- the first argument lists valid *initial* characters<br>- the second argument lists valid *body* or subsequent characters<br><br>For example, in the identifier definition,
<br><br>identifier = pp.Word(pp.alphas, pp.alphanums + &quot;_/:.&quot;)<br><br>identifiers *must* start with an alphabetic character, and then may be<br>followed by 0 or more alphanumeric or _/: or . characters.&nbsp;&nbsp;If only one
<br>argument is supplied, then the same string of characters is used as both<br>initial and body.&nbsp;&nbsp;Identifiers are very typical for 2 argument Word's, as<br>they often start with alphas, but then accept digits and other punctuation.
<br>No whitespace is permitted within a Word.&nbsp;&nbsp;The Word matching will end when a<br>non-body character is seen.<br><br>Using this definition:<br><br>integer = pp.Word(pp.nums+&quot;-+.&quot;, pp.nums)<br><br>It will accept &quot;+123&quot;, &quot;-345&quot;, &quot;678&quot;, and &quot;.901&quot;.&nbsp;&nbsp;But in a real number, a
<br>period may occur anywhere in the number, not just as the initial character,<br>as in &quot;3.14159&quot;.&nbsp;&nbsp;So your bodyCharacters must also include a &quot;.&quot;, as in:<br><br>integer = pp.Word(pp.nums+&quot;-+.&quot;, 
pp.nums+&quot;.&quot;)<br><br>Let me say, though, that this is a very permissive definition of integer -<br>for one thing, we really should rename it something like &quot;number&quot;, since it<br>now accepts non-integers as well!&nbsp;&nbsp;But also, there is no restriction on the
<br>frequency of body characters.&nbsp;&nbsp;This definition would accept a &quot;number&quot; that<br>looks like &quot;3.4.3234.111.123.3234&quot;.&nbsp;&nbsp;If you are certain that you will only<br>receive valid inputs, then this simple definition will be fine.&nbsp;&nbsp;But if you
<br>will have to handle and reject erroneous inputs, then you might do better<br>with a number definition like:<br><br>number = Combine( Word( &quot;+-&quot;+nums, nums ) +<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Optional(
point + Optional( Word( nums ) ) ) )<br><br>This will handle &quot;+123&quot;, &quot;-345&quot;, &quot;678&quot;, and &quot;0.901&quot;, but not &quot;.901&quot;.&nbsp;&nbsp;If you<br>want to accept numbers that begin with &quot;.&quot;s, then you'll need to tweak this
<br>a bit further.<br><br>One last thing: you may want to start using setName() on some of your<br>expressions, as in:<br><br>number = Combine( Word( &quot;+-&quot;+nums, nums ) +<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Optional(
point + Optional( Word( nums ) ) )<br>).setName(&quot;number&quot;)<br><br>Note, this is *not* the same as setResultsName.&nbsp;&nbsp;Here setName is attaching a<br>name to this pattern, so that when it appears in an exception, the name will
<br>be used instead of an encoded pattern string (such as W:012345...).&nbsp;&nbsp;No need<br>to do this for Literals, the literal string is used when it appears in an<br>exception.<br><br>-- Paul<br><br><br></blockquote></div><br>
<br clear="all"><br>-- <br>'There is only one basic human right, and that is to do as you damn well please.<br>And with it comes the only basic human duty, to take the consequences.'