1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#!/usr/local/bin/python
""" Loop - loop examples (Version 0.1)
Copyright (c) 2000, Marc-Andre Lemburg; mailto:mal@lemburg.com
Copyright (c) 2000-2014, eGenix.com Software GmbH; mailto:info@egenix.com
See the documentation for further information on copyrights,
or contact the author. All Rights Reserved.
"""
import sys
# engine + constants
from mx.TextTools import *
# use Loop to match a certain number of subtags
table1 = ((None,Word,'loop '),
# match <= 5 stars
('loop',Loop,5,+4),
(None,Is,'*',+1,-1),
(None,LoopControl,Break),
(None,Jump,To,-3),
# must end with a dot
(None,Is,'.'))
# use Loop to tag subsections of a tagging table, i.e.
# emulate a Table-match
table2 = (('presection',AllNotIn,'(',+1),
# match a group of characters enclosed in ()
('section',Loop,1,+4),
(None,Is,'('),
(None,AllNotIn,')'),
(None,Is,')',0,-3),
# must end with a dot
(None,Is,'.'))
# read in all chars and then do lots of null loops
table3 = (('Loops',Loop,10000,MatchOk),
(None,AllNotIn,'',-1,-1))
text = raw_input('loop-example (e.g. "loop *."): ')
result, taglist, nextindex = tag(text,table1)
print 'result =',result,'-- rest of text:',text[nextindex:]
if result:print_tags(text,taglist)
text = raw_input('section-example( e.g. "myfun(params)."): ')
result, taglist, nextindex = tag(text,table2)
print 'result =',result,'-- rest of text:',text[nextindex:]
if result:print_tags(text,taglist)
text = raw_input('null-loops-example (e.g. "some chars"): ')
result, taglist, nextindex = tag(text,table3)
print 'result =',result,'-- rest of text:',text[nextindex:]
if result:print_tags(text,taglist)
|