summaryrefslogtreecommitdiff
path: root/scheme/make_sweet_macros.py
blob: a7c295b4eab428bb660e077d52a4220c32f9b875 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
import os, sys, shutil
from scheme2rst import SNIPPET

ikarus_code = file('sweet-macros/main.sls').read()

# GUARDED-SYNTAX-CASE, SYNTAX-MATCH, DEF-SYNTAX, SYNTAX-EXPAND
snippets = [s.groups() for s in SNIPPET.finditer(ikarus_code)]
snippet = dict(snippets)

helper1 = '''#!r6rs
(library (sweet-macros helper1)
(export guarded-syntax-case)
(import (rnrs))

%(GUARDED-SYNTAX-CASE)s
)
'''

helper2 = '''#!r6rs
(library (sweet-macros helper2)
(export syntax-match)
(import (rnrs) (for (rnrs) (meta -1))
(for (sweet-macros helper1) (meta -1) (meta 0) (meta 1)))

%(SYNTAX-MATCH)s
)
'''

helper3 = '''#!r6rs
(library (sweet-macros helper3)
(export syntax-match def-syntax)
(import (rnrs) (for (sweet-macros helper2) run expand))

%(DEF-SYNTAX)s
)
'''

main = '''#!r6rs
(library (sweet-macros)
(export syntax-match def-syntax syntax-expand)
(import (rnrs) (for (sweet-macros helper3) run expand))

%(SYNTAX-EXPAND)s
)
'''

def write_on(fname, code):
    file(fname, 'w').write(code)
    os.system('zip sweet-macros %s' % fname)
    
def makefiles(name, snippet):
    write_on(name + '/main.sls', ikarus_code)
    write_on(name + '/main.mzscheme.sls', main % snippet)
    write_on('sweet-macros.larceny.sls', main % snippet)
    write_on('sweet-macros.mosh.sls', ikarus_code)
    write_on(name + '/helper1.sls', helper1 % snippet)
    write_on(name + '/helper2.sls', helper2 % snippet)
    write_on(name + '/helper3.sls', helper3 % snippet)
    
if __name__ == '__main__':
    #plt_home = os.path.expanduser('~/.plt-scheme')
    #collects = os.path.join(plt_home, max(os.listdir(plt_home)), 'collects')
    makefiles('sweet-macros', snippet)
    os.system('scp sweet-macros.zip '
              'micheles@merlin.phyast.pitt.edu:public_html/scheme')