Line | |
---|
1 | ''' |
---|
2 | Created on Jun 12, 2012 |
---|
3 | |
---|
4 | @author: Pete |
---|
5 | ''' |
---|
6 | |
---|
7 | |
---|
8 | import re |
---|
9 | |
---|
10 | # http://www.greenend.org.uk/rjk/tech/regexp.html |
---|
11 | |
---|
12 | spec_func_sig_re = re.compile( |
---|
13 | r'''^ ([a-zA-Z_]\w*) # macro name |
---|
14 | ((\s+\S+)*) # optional: arguments |
---|
15 | $ # and nothing more |
---|
16 | ''', re.VERBOSE) |
---|
17 | |
---|
18 | test_group = """ |
---|
19 | example_runtime_defined_macro content |
---|
20 | test_macro2 arg1 1.0 2 3 |
---|
21 | simple_macro |
---|
22 | _do_this 4 5 7 |
---|
23 | 5testmacro |
---|
24 | """ |
---|
25 | |
---|
26 | for phrase in test_group.split("\n"): |
---|
27 | print "testing:", phrase, "\t --> ", |
---|
28 | m = spec_func_sig_re.match(phrase) |
---|
29 | if m is None: |
---|
30 | print "no match" |
---|
31 | else: |
---|
32 | name, args, last = m.groups() |
---|
33 | print name, args.strip().split() |
---|
Note: See
TracBrowser
for help on using the repository browser.