Mercurial > hg > forks > multipaint-js
view postprocess.pl @ 116:1180249d713d
Add some comments to the postprocess script.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 06 Jul 2018 19:43:56 +0300 |
parents | 62f21240ff63 |
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; }