-
Notifications
You must be signed in to change notification settings - Fork 0
/
to-srfi
executable file
·67 lines (52 loc) · 1.55 KB
/
to-srfi
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
66
#!/usr/bin/perl
# to-srfi - make a Java ".g" file ready for insertion into a Scheme SRFI.
# It filters stdin to translate its action rules into Scheme and
# escape HTML-special names.
# Intended for use on sweet.g, so that we can write in Java (for ANTLR)
# and show Scheme syntax to everyone else.
# This is a very simplistic textual translation.
# This approach does not work in general, but since the input is
# simple, stylized, and controlled by us, it works just fine in this case.
# This presumes that lines with action rules have a "{" or "}" on the line.
$translate = 1;
$include_in_srfi = 0;
while (<>) {
if (/PARSER SECTION/) {
$translate = 1;
}
if (/INCLUDE IN SRFI/) {
$include_in_srfi = 1;
}
if (/STOP INCLUDING IN SRFI/) {
$include_in_srfi = 0;
}
if ($translate && /[{}]/) {
s/([a-z0-9_]+)\(\)/(\1)/g;
s/([a-z0-9_]+)\(/(\1 /g;
s/{ ?\$v ?= ?/{/g;
s/ ?; ?}/}/g;
s/\.v\b//g;
s/\bnull\b/'()/g;
s/"vector"/'vector/;
s/"bytevector"/'bytevector/;
s/"quote"/'quote/;
s/"quasiquote"/'quasiquote/;
s/"unquote-splicing"/'unquote-splicing/;
s/"unquote"/'unquote/;
# Serious hack to remove commas as parameter separators; only do this
# if it appears commas are being used as separators.
s/, / /g if ( /\(.*,.*\)/ ) ;
# Special case.
s/\(list "."\)/(list '.)/g;
s/\{"."\}/{'.}/g;
s/{greedy=false}/{greedy=false;}/g;
}
s/ returns \[Object v\]//;
s/\&/&/g;
s/</</g;
s/>/>/g;
s/\r//g;
if ($include_in_srfi && (! /INCLUDE IN SRFI/)) {
print;
}
}