Funcparserlib

An Introduction

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

stamp = p.skip(p.a('[')) + decimal + p.skip(p.a(']')) >> (lambda x:('time', x))
# p.skip(p.a()) is annoying
char = lambda c: p.skip(p.a(c))
stamp = char('[') + decimal + char(']') >> (lambda x:('time', x))
stamp.parse('[4.5]') == ('time', 4.5)

relstamp = char('[') + char('+') + decimal + char(']') >> (lambda x:('reltime', x))
# char() + char() is annoying
literal = lambda s: reduce(lambda x,y: x+y, map(char, s))
relstamp = literal('[+') + decimal + char(']') >> (lambda x:('reltime', x))
relstamp.parse('[+0.5]') == ('reltime', 0.5)

# those lambdas are getting annoying
tag = lambda t: lambda x:(t, x)

delay = literal('[++') + decimal + char(']') >> tag('delay')
color = char('[') + integer + char(']') >> tag('color')
jump = char('[') + integer + char(',') + number + char(']') >> tag('jump')
newline = literal('[n]') >> tag('newline')
clear = literal('[c]') >> tag('clear')
rgb = ...  # very similar to jump, but longer
clear.parse('[c]') == ('clear', _Ignored(()))
Name:
Mail: (not shown)

Please type this: