- 
      
- 
        Save ManDeJan/696c9a62f6fff862fc1dff025d0d70e4 to your computer and use it in GitHub Desktop. 
    better_python3
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/usr/bin/env perl | |
| # This adds the post-inc, post-dec, pre-inc and pre-dec operators to python! | |
| # Additionally, it supports the -O3 optimization feature. | |
| # Test! :) | |
| my $optimized = 0; | |
| if (@ARGV and $ARGV[0] eq '-O3') { | |
| shift; | |
| $optimized = 1; | |
| } | |
| open my $python, '|-', '/usr/bin/python3', '-' or die "boooo $1"; | |
| while (<>) { | |
| s/^(\s*)([^#]*)(\w+)\s*\+\+(.*)/$1$2$3$4\n$1$3 += 1/; | |
| s/^(\s*)([^#]*)\+\+\s*(\w+)(.*)/$1$3 += 1\n$1$2$3$4/; | |
| s/^(\s*)([^#]*)(\w+)\s*--(.*)/$1$2$3$4\n$1$3 -= 1/; | |
| s/^(\s*)([^#]*)--\s*(\w+)(.*)/$1$3 -= 1\n$1$2$3$4/; | |
| next if $optimized and rand > 0.8; | |
| print $python $_; | |
| } | |
| # Example python script: | |
| # | |
| # y = 0 | |
| # for i in range(0, 5): | |
| # print(i, ++y) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment