3 import srclexer
, srcparser
, globals
8 def run (tokens
, defines
):
9 mcExpander
= srcparser
.MacroExpander(tokens
, defines
)
10 mcExpander
.debug
= True
12 tokens
= mcExpander
.getTokens()
17 tokens
= ['FUNC_FOO', '(', 'left', ',', 'right', ')']
19 macro
= globals.Macro('FUNC_FOO')
20 macro
.tokens
= ['Here', 'comes', 'X', 'and', 'Y']
21 defines
['FUNC_FOO'] = macro
22 TestCase
.run(tokens
, defines
)
26 tokens
= ['FUNC_FOO', '(', 'left', ',', 'right', ')']
28 macro
= globals.Macro('FUNC_FOO')
29 macro
.tokens
= ['Here', 'comes', 'X', 'and', 'Y']
32 defines
['FUNC_FOO'] = macro
33 TestCase
.run(tokens
, defines
)
36 def multiTokenArgs ():
37 tokens
= ['FUNC_FOO', '(', 'left1', 'left2', 'left3', ',', 'right', ')']
39 macro
= globals.Macro('FUNC_FOO')
40 macro
.tokens
= ['Here', 'comes', 'X', 'and', 'Y']
43 defines
['FUNC_FOO'] = macro
44 TestCase
.run(tokens
, defines
)
47 def nestedTokenArgs ():
48 tokens
= ['FUNC_BAA', '(', 'left', ',', 'right', ')']
50 macro
= globals.Macro('FUNC_FOO')
51 macro
.tokens
= ['Here', 'comes', 'X', 'and', 'Y']
54 defines
['FUNC_FOO'] = macro
55 macro
= globals.Macro('FUNC_BAA')
56 macro
.tokens
= ['FUNC_FOO']
57 defines
['FUNC_BAA'] = macro
58 TestCase
.run(tokens
, defines
)
61 print "simple expansion with no arguments"
62 TestCase
.simpleNoArgs()
63 print "simple argument expansion"
65 print "multi-token argument expansion"
66 TestCase
.multiTokenArgs()
67 print "nested argument expansion"
68 TestCase
.nestedTokenArgs()
70 if __name__
== '__main__':