A service routine, this function removes a floating-point
number from the head of s.
# - - - p a r s e F l o a t
def parseFloat ( s, message ):
"""Parse a floating-point number at the front of s.
[ (s is a string) and
(message is a string describing what is expected) ->
if s begins with a floating-point number ->
return (x, tail) where x is the number as type float
and tail is the part of s after the match
else -> raise SyntaxError, "Expecting (message)" ]
"""
We use the precompiled regular expression from Section 8.6, “FLOAT_PAT: Regular expression for a
floating-point number” to match the number.
#-- 1 --
# [ if the front of s matches FLOAT_PAT ->
# m := a Match object describing the match
# else -> raise SyntaxError ]
rawFloat, tail = parseRe ( s, FLOAT_PAT, message )
The matching string is available as m.group().
The position just after the match is available as m.end().
#-- 2 --
return (float(rawFloat), tail)