source: specdomain/trunk/src/specdomain/test/tester3.py

Last change on this file was 979, checked in by jemian, 10 years ago

refs #8, tester4.py defines matches for macro declarations in source files

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 774 bytes
Line 
1#!/usr/bin/env python
2
3
4'''
5$Id: tester3.py 979 2012-06-26 05:14:24Z jemian $
6
7test various regular expressions to match macro declaration signatures
8'''
9
10
11import re
12
13# http://www.greenend.org.uk/rjk/tech/regexp.html
14
15spec_func_sig_re = re.compile(
16    r'''^ ([a-zA-Z_]\w*)         # macro name
17          ((\s+\S+)*)            # optional: arguments
18          $                      # and nothing more
19          ''', re.VERBOSE)
20
21test_group = """
22example_runtime_defined_macro content
23test_macro2 arg1   1.0 2     3
24simple_macro
25_do_this    4    5    7
265testmacro
27"""
28
29for phrase in test_group.split("\n"):
30    print "testing:", phrase, "\t --> ",
31    m = spec_func_sig_re.match(phrase)
32    if m is None:
33        print "no match"
34    else:
35        name, args, last = m.groups()
36        print name, args.strip().split()
Note: See TracBrowser for help on using the repository browser.