forked from PLSE-Lab/go2rascal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertTokens.awk
More file actions
99 lines (86 loc) · 2.77 KB
/
convertTokens.awk
File metadata and controls
99 lines (86 loc) · 2.77 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
BEGIN {
goTokenListLen=0;
rascalTokenListLen=0;
delete goTokenList;
delete rascalTokenList;
goType="";
tokenType="";
print "package main"
print "import ("
print "\t\"fmt\""
# print "\t\"go/ast\""
print "\t\"go/token\""
print ")"
print ""
}
NF == 1 && tokenType != "" && goType != "" {
# print "reset line " $0
print "func " tokenType "ToRascal(node " goType ") string {"
print "\tswitch node {"
i=0;
for (idx in goTokenList) {
print "\tcase " goTokenList[idx] ":"
print "\t\treturn " rascalTokenList[idx]
}
print "\tdefault:"
print "\t\tpanic(fmt.Sprintf(\"unknown" toupper(substr(tokenType, 1, 1)) substr(tokenType, 2) "(\\\"%s\\\")\", node.String()))"
print "\t}"
print "}"
print ""
print "func rascal" toupper(substr(tokenType, 1, 1)) substr(tokenType, 2) "ToGo(rascal" toupper(substr(tokenType, 1, 1)) substr(tokenType, 2) " string) " goType " {"
print "\tswitch rascal" toupper(substr(tokenType, 1, 1)) substr(tokenType, 2) "{"
for (idx in goTokenList) {
print "\tcase " rascalTokenList[idx] ":"
print "\t\treturn " goTokenList[idx]
}
print "\tdefault:"
print "\t\tpanic(fmt.Sprintf(\"unknown" toupper(substr(tokenType, 1, 1)) substr(tokenType, 2) "(\\\"%s\\\")\", rascal" toupper(substr(tokenType, 1, 1)) substr(tokenType, 2) "))"
print "\t}"
print "}"
print ""
goTokenListLen=0;
rascalTokenListLen=0;
delete goTokenList;
delete rascalTokenList;
goType="";
tokenType="";
}
NF == 1 && goType == "" && tokenType != "" {
goType=$1;
# print "goType " goType
}
NF == 1 && tokenType == "" {
tokenType=$1;
# print "tokenType " tokenType
}
# this will get assigned twice but I don't care
NF == 2 {
goTokenList[goTokenListLen]=$1;
rascalTokenList[rascalTokenListLen]=$2;
goTokenListLen++;
rascalTokenListLen++;
}
END {
print "func " tokenType "ToRascal(node " goType ") string {"
print "\tswitch node {"
i=0;
for (idx in goTokenList) {
print "\tcase " goTokenList[idx] ":"
print "\t\treturn " rascalTokenList[idx]
}
print "\tdefault:"
print "\t\tpanic(fmt.Sprintf(\"unknown" toupper(substr(tokenType, 1, 1)) substr(tokenType, 2) "(\\\"%s\\\")\", node.String()))"
print "\t}"
print "}"
print ""
print "func rascal" toupper(substr(tokenType, 1, 1)) substr(tokenType, 2) "ToGo(rascal" toupper(substr(tokenType, 1, 1)) substr(tokenType, 2) " string) " goType " {"
print "\tswitch rascal" toupper(substr(tokenType, 1, 1)) substr(tokenType, 2) "{"
for (idx in goTokenList) {
print "\tcase " rascalTokenList[idx] ":"
print "\t\treturn " goTokenList[idx]
}
print "\tdefault:"
print "\t\tpanic(fmt.Sprintf(\"unknown" toupper(substr(tokenType, 1, 1)) substr(tokenType, 2) "(\\\"%s\\\")\", rascal" toupper(substr(tokenType, 1, 1)) substr(tokenType, 2) "))"
print "\t}"
print "}"
}