diff --git a/README.md b/README.md index db3e43f..1a4d544 100644 --- a/README.md +++ b/README.md @@ -1,408 +1,161 @@ Introduction ------------ -PythonJS is a transpiler written in Python that converts a python like language into fast -JavaScript. It also includes experimental backends that translate to: Dart, Lua, CoffeeScript, and Go. - -[Syntax Documentation](https://github.com/PythonJS/PythonJS/blob/master/doc/syntax.md) - - -Go backend ----------- -The Go backend uses a fully typed subset of Python, mixed with extra syntax inspired by Golang to output Go programs that can be compiled to native executeables, or translated to JavaScript using GopherJS. +Gython is a transpiler written in Python that converts a python like language into Go. [Syntax Documentation](https://github.com/PythonJS/PythonJS/blob/master/doc/go_syntax.md) -Getting Started +Installing =============== -PythonJS can be run with regular Python, or fully self-hosted within -NodeJS using Empythoned. -To get started, you have two options: -1. install NodeJS, python-js package, and write a build script. -2. or install Python2 and use translator.py from this repo directly. +gython.py +-------------------------------------- +Install Python2.7 and git clone this repo, in the toplevel is the build script `gython.py`. +Running gython.py from the command line and passing it one or more python scripts outputs +the Go translation to stdout. -1. Installing NodeJS Package -------------- -You can quickly get started with the stable version of PythonJS by installing the NodeJS package, -and writing a build script in javascript to compile your python scripts to javascript. -(Python2.7 is not required) +Usage:: -``` -npm install python-js -``` + gython.py file.py -NodeJS Quick Example --------------- +Example:: -``` -var pythonjs = require('python-js'); -var pycode = "a = []; a.append('hello'); a.append('world'); print(a)"; -var jscode = pythonjs.translator.to_javascript( pycode ); -eval( pythonjs.runtime.javascript + jscode ); + git clone https://github.com/gython/Gython.git + cd Gython + ./gython.py myscript.py > myscript.go -``` +Getting Started +=============== +Gython supports classes and multiple inheritance, with method overrides and calling the parent class methods. -Example Projects ----------------- -The example projects below, require the NodeJS python-js package. +``` + class A: + def foo(self) -> int: + return 1 -[https://github.com/PythonJS/pythonjs-demo-server-nodejs](https://github.com/PythonJS/pythonjs-demo-server-nodejs) + class B: + def bar(self) -> int: + return 2 -[https://github.com/PythonJS/pypubjs](https://github.com/PythonJS/pypubjs) + class C( A, B ): + def call_foo_bar(self) -> int: + a = self.foo() + a += self.bar() + return a + def foo(self) -> int: + a = A.foo(self) + a += 100 + return a +``` -2. translator.py --------------------------------------- -If you want to run the latest version of the translator, you will need to install -Python2.7 and git clone this repo. (the NodeJS package above is not required) -Then, to translate your python script, directly run the `translator.py` script in the "pythonjs" directory. You can give it a list of python files to translate at once. -It will output the translation to stdout. The default output type is JavaScript. -An html file can also be used as input, python code inside a script tag: `