Giter Site home page Giter Site logo

mathialo / bython Goto Github PK

View Code? Open in Web Editor NEW
1.3K 19.0 36.0 131 KB

Python with braces. Because python is awesome, but whitespace is awful.

License: MIT License

Python 88.08% Roff 9.32% Shell 0.09% Makefile 2.51%
python whitespace braces indentation bython

bython's People

Contributors

lynnpepin avatar mathialo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bython's Issues

Allow mixing with indented code

I will be working with others on projects and will be maintaining some of their code.

For this it would be nice if I could simply change their code and mix indented code with braced code.

Convert || to or and && to and

Make it easier for those who've written code in other languages by converting && to and and || to or

Consider converting !x to not x but that may be less trivial

Curly brackets

Hi! I'm not a pro at using Python but there seems to be a parsing error for arguments with Bython
I'm trying to pass JSON string as an argument, which works if you use python but breaks when using Bython, the whitespaces and/or the double-quotes in the argument breaks.

sample JSON argument that breaks:
'{"1": [1,2]}'

when the output is printed from sys.argv, it becomes {1:[1,2]} thereby breaks the load function of the JSON

EDIT:

The argument above should have backslashes before the double quotes for it to work properly :)

Thanks!

Dict fails

This fails in Bython

a = { 'a', 'b' }
print("Works in Python")

With:

$ bython test2.py 
  File "python_test2.py.py", line 1
    a =:'a', 'b' 
       ^
SyntaxError: invalid syntax

Consider parsing tokenized version of code

It appears some glitches in bython occur because it's reading the source code as text. It might be more useful to python -m tokenize input.py first and then change the tokenized version

py2by breaks on a lot of valid indentation cases

py2by fails on a lot of valid python indentation cases, including, but not limited to:

No way to express mixed indentation levels, which are valid in python. E.g.:

if (1==1):
    if(2==2):
                print("Oops!")

Indentation that does not impact nesting level. E.g.:

print("Sometimes strings that are too long,",
    "are broken up on different lines.")

I'm considering rewriting py2by utilizing the python tokenizer to detect INDENT and DEDENT tokens. Should be more portable too, should the indentation rules for python ever change

Transpiling?

Hi! I'm new to this project but i'm not sure if bython already supports transpiling to python, instead of just interpreting bython code. This isn't explicitly stated in the readme (to my understanding), so can bython transpile .by to .py?

Bython doesn't work when curly braces are in their own line

As the title suggests, when doing something like this:

def test()
{
     return "test"
}

It gets turned into this, which doesn't work:

def test()
:
     return "test"

I think there was an effort to make this work in line 161 of parser.py:

line = re.sub(r"\n:", ":", line)

However this is applied to lines, it should be applied to infile_str_intdented, like this:

 infile_str_indented = re.sub(r"\n:", ":", infile_str_indented)

Which will fix it

Dictionaries doesn't work at all

Since dictionaries uses curly braces they will cause a lot of errors when translating from bython to python. Dictionaries in python-files you import works.

lines with "}"

Lines with "}" can't have stuff behind them. The following code doesn't run:

if condition {
    pass
} else {
    pass
}

but must instead be written as

if condition {
    pass
}
else {
    pass
}

Also get rid of forced newlines?

I was trying to use bython for newliners. I found that in addition to #33, there's another problem. Consider the following program:

m=0; for line in __import__("sys").stdin { m = m if m > int(line.strip()) else int(line.strip())} ; print(m)

This only works if m=0 has its own line. Could this limitation be lifted?

Import transpilation?

Is it possible to hack the Python import system to import Bython code, just like how we could do register hooks on Node? I don't want to transpile it all the time beforehand you know...

There's a proposal of adding a new import hook in Python, but it has been staggered for like 16 years. I don't know it that's relevant. Maybe we should exploit ImportError and then get the transpiled code injected there...

But I don't know Python at all, anyway.

Mixed mode

I want this to work:

#!/usr/bin/env bython

def a():
  print("a")

def b() {
if 4<5:
  print("b")
}

a()
b()

The situation here is: I get a Python script that I edit. Most of it is white-space indented correctly. But parts of it use braces.

In particular I need braces to paste-in a section. In the above I got the if and print statements from another source with different indention. So I simply wrapped it with {} and this should then be understood correctly.

So I am asking for a mixed mode, where indention matters if there are no braces overriding it.

error when trying to install

im getting this in terminal when i try to install following instructions in the readme:
Makefile:5: recipe for target 'install' failed
make: *** [install] Error 1

is this a problem on my end or something with the makefile?

Formatting Bython code?

I would like to enable auto-format-on-save for my IDE but can't find a way to format bython.

I thought by2py example.by && py2by example.py && rm example.py would achieve what I'm looking for, but it generates some additional newlines etc.

py2by also doesn't overwrite the existing example.by so it would have to be done with rm example.by between by2py & py2by. Deleting the file would probably mess up the IDE, 'in place' replacement would be preferable.

Input:

def print_message(num_of_times) {
 for i in range(num_of_times) {
print("Bython is awesome!");
          }
}

if __name__ == "__main__" {
    print_message(10);
}

After by2py:

def print_message(num_of_times):
    for i in range(num_of_times):
        print("Bython is awesome!")



if __name__ == "__main__":
    print_message(10)


After py2by:

def print_message(num_of_times){
    for i in range(num_of_times){
        print("Bython is awesome!")



    }
}
if __name__ == "__main__"{
    print_message(10)


}

Bootstrapping

Bython should be able to parse itself, and not rely on filthy regular python in doing so!

Man page missing

There are many options in the source which is not covered by README. It would be good to put those in a man page.

Windows install?

I'm trying to install Bython on windows with Python 3.7.1, by using pip install bython in the Windows admin command prompt. Pip reports it as installed, but the command prompt won't recognize the bython
command. Am I doing something wrong?

Set initializers should work for bython

import os

def main(){
  c= {1,3}
  print('hello')
  print({'A':1,
        'b':2}
        )
}
main()

Fails with

  File "python_main.py", line 4
    c=:1,3
    ^
IndentationError: expected an indented block

Dictionaries no longer work.

The compiler seems to have issues working with Python dictionaries. It converts the left curly brace to a colon.

Merge pull requests?

Last commit is from 2018, it would be nice to have the improvements implemented

Multiline lambdas?

Hi there!

One of my main gripes about Python is not being able to write multiline lambdas. I had an idea to create a Python preprocessor that allows braces (and found this before making it myself) to allow multiline lambdas, but also to generally improve readability.

I'm just wondering if Bython supports multiline lambdas, or plans to in the future.

Thanks so much!

Converter from indented code to braced

When working with files written by others it would be nice if you could convert their code to braced code.

By being able to convert both ways you open up for making an emacs-filter that inserts braces when opening a file and removes them when saving the file. Give that emacs can run .gz-files through a filter it ought to be easy to do that for .py-files, too.

PS: And thank you. I have been holding off using Python for anything serious because of the missing braces. Now that hurdle is gone.

comments inlined with functions cause a syntax error

def test(x): #prints x
     print(x)

is converted to

def test(x) #prints x
{
    print(x);
}

which when run is converted to

def text(x) #prints x:
    print(x)

which causes a syntax error because the : is commented out.

Bython modifies braces within strings.

Bython v0.8 exhibits a problem in which it modifies braces within single and double quotation strings.

Code to reproduce:

test.by:
print('Hello, world! I have braces {} here.');
print("Hello, world! I have braces {} here, too.");

The output produced is:
Hello, world! I have braces:here.
Hello, world! I have braces:here, too.

The expected output is, of course:
Hello, world! I have braces {} here.
Hello, world! I have braces {} here, too.

Thanks!

Fantastic!

You, my good sir, are a magnificent bastard for doing this!

Though I am unfit to touch the hem of your garment, as your disciple I will go forth and hail this good news unto the multitudes.

[Request] Help writing my bython syntax module for vim

Hi! I've made a rudementary syntax highlighting module for vim, and am requesting for help with writing the indenting code. I know I can use a variant of vim's native cindent feature, but other than that, I'm stumped as how to made semicolons optional.

by2py Bug: Removes every colon

Here's a python snippet:

print("Hello World: !")

Running py2by on this snippet results in:

print("Hello World !")

The documentation explains that py2by is experimental- but I'd like to report this bug. Maybe there's an easy fix?

I discovered this bug when py2by-ing a souce file with type annotations (they break).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.