All Projects → pseudo-lang → Pseudo

pseudo-lang / Pseudo

Licence: mit
transpile algorithms/libs to idiomatic JS, Go, C#, Ruby

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pseudo

sqlglot
Python SQL Parser and Transpiler
Stars: ✭ 310 (-52.6%)
Mutual labels:  translation, transpiler
C2rust
Migrate C code to Rust
Stars: ✭ 2,111 (+222.78%)
Mutual labels:  transpiler, translation
Termit
Translations with speech synthesis in your terminal as a ruby gem
Stars: ✭ 505 (-22.78%)
Mutual labels:  translation
Fluent.js
JavaScript implementation of Project Fluent
Stars: ✭ 622 (-4.89%)
Mutual labels:  translation
Sf Zh
《软件基础》中译版 Software Foundations Chinese Translation
Stars: ✭ 554 (-15.29%)
Mutual labels:  translation
Rust Bert
Rust native ready-to-use NLP pipelines and transformer-based models (BERT, DistilBERT, GPT2,...)
Stars: ✭ 510 (-22.02%)
Mutual labels:  translation
Cppcoreguidelines
C++ 핵심 가이드라인 한글화 프로젝트 (C++ Core Guidelines)
Stars: ✭ 572 (-12.54%)
Mutual labels:  translation
Angular Translate
Translating your AngularJS 1.x apps
Stars: ✭ 4,414 (+574.92%)
Mutual labels:  translation
Seq2seq
A general-purpose encoder-decoder framework for Tensorflow
Stars: ✭ 5,455 (+734.1%)
Mutual labels:  translation
Aspnetcore Doc Cn
The Simplified Chinese edition of Microsoft ASP.NET Core documentation, translated by .NET Core Community and .NET China Community.
Stars: ✭ 527 (-19.42%)
Mutual labels:  translation
Javascript Airbnb
Перевод «JavaScript Style Guide» от Airbnb
Stars: ✭ 579 (-11.47%)
Mutual labels:  translation
What the thing
📷 Point your camera at things to learn how to say them in a different language. Android app built with React Native.
Stars: ✭ 526 (-19.57%)
Mutual labels:  translation
You Dont Know Js Ru
📚 Russian translation of "You Don't Know JS" book series
Stars: ✭ 5,671 (+767.13%)
Mutual labels:  translation
Androbd
Android OBD diagnostics with any ELM327 adapter
Stars: ✭ 573 (-12.39%)
Mutual labels:  translation
Flex
The minimalist Pelican theme.
Stars: ✭ 510 (-22.02%)
Mutual labels:  translation
Retro Board
Retrospective Board
Stars: ✭ 622 (-4.89%)
Mutual labels:  translation
Translation.js
集成了谷歌翻译、有道翻译与百度翻译的网页翻译接口,可在 Node.js 与 Chrome 扩展 / 应用中使用。
Stars: ✭ 493 (-24.62%)
Mutual labels:  translation
Universal Starter
Angular 9 Universal repo with many features
Stars: ✭ 518 (-20.8%)
Mutual labels:  translation
Rapydscript
Python-inspired, decluttered JavaScript
Stars: ✭ 560 (-14.37%)
Mutual labels:  transpiler
Mobility
Pluggable Ruby translation framework
Stars: ✭ 644 (-1.53%)
Mutual labels:  translation

Build Status codecov.io MIT License

pseudo

Join the chat at https://gitter.im/alehander42/pseudo

Pseudo takes an algorithm / a simple program and generates idiomatic code for it in Python, JavaScript, C#, Go and Ruby.

Pseudo achieves that with translation on two layers: it uses the target language syntax and it can express standard library methods/api of language X using language Y's native standard library

git history

Sorry: I lied, remaking the git history in a way that it appears most of the work is after 1 march: I was finishing my work in a company in february and I wanted to hide the fact i've worked on pseudo in that time: I actually started more active work somewhere around 20-th february if I remember correctly, somewhere around the second half of february. I am not sure if i have that original git history anymore: sorry to Clevertech(the company)/any observers, this was a really ugly thing to do.

concept

Pseudo consumes "Pseudo AST" which corresponds to a very clear, statically typed and somehow limited subset of a language:

  • basic types and collections and standard library methods for them

  • integer, float, string, boolean

  • lists

  • dicts

  • sets

  • tuples/structs(fixed length heterogeneous lists)

  • fixed size arrays

  • regular expressions

  • functions with normal parameters (no default/keyword/vararg parameters)

  • classes

    • single inheritance
    • polymorphism
    • no dynamic instance variables
    • basically a constructor + a collection of instance methods, no fancy metaprogramming etc supported
  • exception-based error handling with support for custom exceptions (target languages support return-based error handling too)

  • I/O: print/input, file read/write, command arg handling, system and subprocess commands

  • iteration (for-in-range / for-each / iterating over several collections / while)

  • conditionals (if / else if / else)

  • standard math/logical operations

  • a lot more in future

standard library reference

Those constructs and entities have almost the same behavior and very same-spirited api in a lot of the languages which Pseudo would support.

examples

Each example contains a detailed README and working translations to Python, JS, Ruby, Go and C#, generated by Pseudo

fibonacci

a football results processing command line tool

a verbal expressions-like library ported to all the target languages

architecture

PSEUDO AST:
   NORMAL CODE     PSEUDO STANDARD LIBRARY INVOCATIONS     
      ||                    ||
      ||                    ||
      ||              API TRANSLATOR
      ||                    ||
      ||                    ||
      ||                    \/
      ||              IDIOMATIC TARGET LANGUAGE 
      ||              STANDARD LIBRARY INVOCATIONS        
      ||                    ||     
      \/                    \/
  STANDARD OR LANGUAGE-SPECIFIC MIDDLEWARES
              e.g.
    name camel_case/snake_case middleware
    convert-tuples-to-classes middleware
    convert-exception-based errors handling
    to return-based error handling middleware
              etc

              ||
              ||
              ||
              ||
  TARGET LANGUAGE CODE GENERATOR

      defined with a dsl aware
      that handles formatting
         automatically
              ||
              ||
              ||
              \/

      Python / C# / Go / JS / Ruby

use cases

  • generate code for the same task/algorithm in different languages (parser generators etc)
  • port a library/codebase
  • develop core logic in one language and use it in other language codebases
  • write a compiler/dsl
  • bootstrap a codebase in another language / generate equivalent test suites in different languages
  • translate/support some algorithms in different languages
  • translate/support some text/data processing/command tool in different languages

installation

pip install pseudo #only python 3 supported

# probably you'd like to try the python-to-pseudo-to-js/go/etc compiler
pip install pseudo-python

usage

you can directly generate pseudo ast from Python using Pseudo-Python

pseudo-python a.py # generates a.pseudo.yaml

and then translate the ast

pseudo a.pseudo.yaml go # or ruby / js / csharp / py / cpp

or you can directly translate from python to another language

pseudo-python a.py b.rb # or c.cs
pseudo.generate(pseudo_ast, language) # pseudo_ast is a plain dict or a pseudo Node-based tree
pseudo.generate_from_yaml(pseudo_ast, language) # pseudo_ast is yaml-encoded pseudo ast

For quick experiments it's easier to use generate_main

from pseudo import * # ok for a repl

print(generate_main([
  assignment(
    local('a', 'Int'),
    call(local('g'), [to_node(0), to_node('')], 'Int'))], 'rb'))

a = g(0, '')

In the future Pseudo can add a lisp-like dsl for fast manual creation of ast nodes, but currently it's more useful for its main goal: consuming automatically generated pseudo ast and then transpiling it to the target languages.

why?

Supporting full-blown Ruby to Python/Javascript to C++ auto translation is hard.

However often we need to just express an algorithm, a self-contained core of a library, a simple command line tool and the act of manual porting to another languages feels somehow .. primitive.

Often that code is(or can be) expressed in very similar way, with similar constructs and basic types and data structures. On that level a lot of languages are very similar and the only real difference is syntax and methods api. That's a feasible task for automatic translation and actually the existance of pseudo is to fullfill the needs of several other existing projects/ideas.

Another powerful thing about Pseudo is its standard library. It can accumulate a serious number of methods/idioms and it can act like e.g. a truly cross-platform, target-language-aware equivalent of lodash

Pseudo is still young (it's basically less than two weeks old), but it already has a base on which it can improve really quickly (adding support for another language is basically just a matter of 3-4 hours currently)

Language support

Using pseudo's DSL it's easy to add support for a new language, so it's feasible to expect support for most popular languages and even different versions of them (e.g. EcmaScript 6/7, Perl 5/6 Java 7 / 8)

Compilers targetting pseudo

Currently pseudo-python is usable, and there are plans for pseudo-ruby or pseudo-js

Intermediate AST format

The AST format uses basic data structures available in most languages. The nodes correspond to dictionaries with type key corresponding to the node type and field_name keys corresponding to the node fields, similar to the widely popular estree ecmascript format.

Pseudo can consume ast either serialized in .pseudo.yaml files or directly as dictionary objects through it's pseudo.generate(ast, output_lang) API

Implementation

The implementation goal is to make the definitions of new supported languages really clear and simple.

If you dive in, you'll find out a lot of the code/api transformations are defined using a declarative dsl with rare ocassions of edge case handling helpers.

That has a lot of advantages:

  • Less bugs: the core transformation code is really generalized, it's reused as a dsl and its results are well tested

  • Easy to comprehend: it almost looks like a config file

  • Easy to add support for other languages: I was planning to support just python and c# in the initial version but it is so easy to add support for a language similar to the current supported ones, that I added support for 4 more.

  • Easy to test: there is a simple test dsl too which helps all language tests to share input examples like that

However language translation is related to a lot of details and a lot of little gotchas, tuning and refining some of them took days. Pseudo uses different abstractions to streamline the process and to reuse logic across languages.

PSEUDO AST:
   NORMAL CODE     PSEUDO STANDARD LIBRARY INVOCATIONS     
      ||                    ||
      ||                    ||
      ||              API TRANSLATOR
      ||                    ||
      ||                    ||
      ||                    \/
      ||              IDIOMATIC TARGET LANGUAGE 
      ||              STANDARD LIBRARY INVOCATIONS        
      ||                    ||     
      \/                    \/
  STANDARD OR LANGUAGE-SPECIFIC MIDDLEWARES
              e.g.
    name camel_case/snake_case middleware
    convert-tuples-to-classes middleware
    convert-exception-based errors handling
    to return-based error handling middleware
              etc

              ||
              ||
              ||
              ||
  TARGET LANGUAGE CODE GENERATOR

      defined with a dsl aware
      that handles formatting
         automatically
              ||
              ||
              ||
              \/

            OUTPUT

Roadmap

Pseudo has undergone some changes through the last year in my local repo, the new release somewhere in the next months should contain some of this roadmap.

Roadmap

Target language specific docs

Pseudo and Haxe

They might seem comparable at a first glance, but they have completely different goals.

Pseudo wants to generate readable code, ideally something that looks like a human wrote it/ported it

Pseudo doesn't use a target language runtime, it uses the target language standard library for everything (except for JS, but even there is uses lodash which is pretty popular and standard)

Pseudo's goal is to help with automated translation for cases like algorithm generation, parser generation, refactoring, porting codebases etc. The fact that you can write compilers targetting Pseudo and receiver translation to many languages for free is just a happy accident

The name?

well.

pseudo(code)

License

Copyright © 2015 2016 Alexander Ivanov

Distributed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].