source: specdomain/trunk/src/specdomain/test/tester6.py @ 1002

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

refs #8, now handle multi-line cdef

File size: 1.6 KB
Line 
1'''
2Created on Jul 11, 2012
3
4@author: Pete
5'''
6
7
8import re
9import pyparsing
10
11
12string_start                = r'^'
13string_end                  = r'$'
14match_all                   = r'.*'
15non_greedy_filler           = match_all + r'?'
16non_greedy_whitespace       = r'\s*?'
17
18spec_cdef_declaration_match_re = re.compile( 
19            r''
20            + non_greedy_filler         # optional any kind of preceding stuff, was \s*? (optional blank space)
21            + non_greedy_whitespace
22            + r'(cdef)'                 # 0: cdef
23            + r'\('                     # opening parenthesis
24#                + r'(.*?)'                 # 1: args (anything between the parentheses)
25            + r'(.*?)'                   # 1: args (anything between the parentheses)
26            + r'\)',                    # closing parenthesis
27            re.DOTALL | re.MULTILINE | re.VERBOSE
28         )
29
30
31barrage = """
32cdef("test1")
33cdef("test2","\nwait(1);\n","waitmove_hack","0x20")
34cdef("test3",
35     "\nwait(1);\n",
36     "waitmove_hack",
37     "0x20")
38cdef("test4", "", "scan_cleanup", "delete")
39cdef("test5", sprintf("dscan_cleanup $1 %s;", _c1), "dscan")
40"""
41
42
43for mo in spec_cdef_declaration_match_re.finditer(barrage):
44    print mo.groups(), mo.start(), mo.end(), mo.span()
45
46print """
47It is not possible to identify properly all these cases with a regular expression
48
49Instead, search for the beginnings of a potential cdef declaration
50'cdef\(' and start watching the code, incrementing and decrementing
51on ( and ) until the counter gets back to zero.
52"""
Note: See TracBrowser for help on using the repository browser.