Mercurial > hg > forks > multipaint-js
view postprocess.pl @ 218:2e077cfc4f38
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 04 Sep 2018 19:24:59 +0300 |
parents | 1180249d713d |
children |
line wrap: on
line source
#!/usr/bin/perl -w # # Perl script for filtering/post-processing the transpiled # ProcessingJS code of Multipaint.JS to remove various uselessly # complicated abstractions/transformations. # # Usage: # 1) use "docompile.html" to transpile Multipaint, save to multipaint.js.orig # 2) run the result through this script: # perl postprocess.pl < multipaint.js.orig > multipaint.js # use strict; use warnings; while (defined(my $line = <STDIN>)) { # The $p.parseByte()s are useless, really $line =~ s@.p\.parseByte\(@(@g; # Transform $p.parseInt(new $p.Character('x')) to direct ASCII number of the character $line =~ s@.p\.parseInt\(\(new\s+.p\.Character\('(.)'\)\)\)@sprintf('%d',ord($1))@eg; # Same for (new $p.Character('x')) $line =~ s@\(new\s+.p\.Character\('(.)'\)\)@sprintf('%d',ord($1))@eg; # Using parseInt() is wasteful, Math.trunc() is more efficient $line =~ s@.p\.parseInt\(@Math.trunc(@g; # Kludge. The switch() in help() in Interface.pde needs this to work after our # previous transformations done in this script. $line =~ s@switch\s*\(.p\.parseChar\(mode\)\)@switch (mode)@g; print $line; }