Funcparserlib

An Introduction

Comments are moderated. It may take a few minutes before your comment appears.
Markdown is supported in your comments.

digits = p.oneplus(p.some(lambda c: c.isdigit()))
digits.parse('123') == ['1', '2', '3']

to_int = lambda ds: sum(int(d)*10**m for m,d in enumerate(reversed(ds)))
to_int(['1', '2', '3']) == 123

integer = digits >> to_int
integer.parse('123') == 123

to_dec = lambda ds: sum(int(d)*10**(-m-1) for m,d in enumerate(ds))
to_dec(['1', '2', '3']) == 0.12300000000000001  # close enough

decimal = integer + p.skip(p.a('.')) + (digits >> to_dec) >> sum
decimal.parse('123.456') == 123.456

numbers = p.many((decimal | integer) + p.skip(p.maybe(p.a(' '))))
numbers.parse('1 2 3 4.5 6 7.5') == [1, 2, 3, 4.5, 6, 7.5]
Name:
Mail: (not shown)

Please type this: