forked from lojban/ilmentufa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-ckt.js
69 lines (65 loc) · 2.43 KB
/
make-ckt.js
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
main(process.argv, require("fs"));
process.exit();
function main(argv, fs) {
if (argv.length < 3) {
console.log("Not enough parameters.");
return;
}
var srcpath = argv[2];
var dstpath = srcpath.replace(/^(.*?)(\.[^\\\/]+)?$/g, "$1-ckt$2");
var peg;
var df;
try {
console.log("Opening " + srcpath);
peg = fs.readFileSync(srcpath).toString();
console.log("Opening " + dstpath);
df = fs.openSync(dstpath, 'w+');
} catch(e) {
console.log("Error: " + e);
}
peg = make_ckt(peg);
fs.writeSync(df, peg, 0, peg.length);
return;
}
function make_ckt(peg) {
// ce → ce'u
peg = peg.replace(/(\nJOI <- &cmavo \( [^\n]*)\/ c e (?=\/|\))/gm, "$1");
peg = peg.replace(/(\nKOhA <- &cmavo \([^\n]*)\)/gm, "$1/ c e )");
// ki'i → ki → ke'a
peg = peg.replace(/(\nBAI <- &cmavo \( [^\n]*)\/ k i h i (?=\/|\))/gm, "$1");
peg = peg.replace(/(\nKI <- &cmavo \() k i \)/gm, "$1 k i h i )");
peg = peg.replace(/(\nKOhA <- &cmavo \([^\n]*)\)/gm, "$1/ k i )");
// tau → tu'a
peg = peg.replace(/(\nLAU <- &cmavo \( [^\n]*)\/ t a u (?=\/|\))/gm, "$1");
peg = peg.replace(/(\nLAhE <- &cmavo \([^\n]*)\)/gm, "$1/ t a u )");
// du → du'u
peg = peg.replace(/(\nGOhA <- &cmavo \( [^\n]*)\/ d u (?=\/|\))/gm, "$1");
peg = peg.replace(/(\nNU <- &cmavo \([^\n]*)\)/gm, "$1/ d u )");
// su'u → su → su'o
peg = peg.replace(/(\nNU <- &cmavo \( [^\n]*)\/ s u h u (?=\/|\))/gm, "$1");
peg = peg.replace(/(\nSU <- &cmavo \() s u \)/gm, "$1 s u h u )");
peg = peg.replace(/(\nPA <- &cmavo \([^\n]*)\)/gm, "$1/ s u )");
// zai → bu'u
peg = peg.replace(/(\nLAU <- &cmavo \( [^\n]*)\/ z a i (?=\/|\))/gm, "$1");
peg = peg.replace(/(\nFAhA <- &cmavo \([^\n]*)\)/gm, "$1/ z a i )");
// koi → ko'oi
peg = peg.replace(/(\nBAI <- &cmavo \( [^\n]*)\/ k o i (?=\/|\))/gm, "$1");
peg = peg.replace(/(\nUI <- &cmavo \([^\n]*)\)/gm, "$1/ k o i )");
// voi → poi'i
peg = peg.replace(/(\nNOI <- &cmavo \() v o i \//gm, "$1");
peg = peg.replace(/(\nNU <- &cmavo \([^\n]*)\)/gm, "$1/ v o i )");
// se'e → zu'ai
peg = peg.replace(/(\nBY <- &cmavo \( [^\n]*)\/ s e h e (?=\/|\))/gm, "$1");
peg = peg.replace(/(\nKOhA <- &cmavo \([^\n]*)\)/gm, "$1/ s e h e )");
return peg;
}
/*
ce'u → ce
ke'a → ki
tu'a → tau
du'u → du
su'o → su
bu'u → zai
ko'oi → koi
poi'i → voi
*/