Manual:Getting Started:Matchers

まんま

>>> from lepl import *
>>> next( Word().match('hello world') )
(['hello'], ' world')
>>> next( Integer().match('123 four five') )
(['123'], ' four five')
>>> next( And(Word(), Space(), Integer()).match('hello 123') )
(['hello', ' ', '123'], '')
>>> next( (Word() & Space() & Integer()).match('hello 123') )
(['hello', ' ', '123'], '')
>>> next( (Word() / Integer()).match('hello 123') )
(['hello', ' ', '123'], '')
>>> (Word() / Integer()).parse_string('hello 123')
['hello', ' ', '123']