pseudo-lang / pseudo Goto Github PK
View Code? Open in Web Editor NEWtranspile algorithms/libs to idiomatic JS, Go, C#, Ruby
License: MIT License
transpile algorithms/libs to idiomatic JS, Go, C#, Ruby
License: MIT License
I've been playing around with similar ideas recently and was considering what kind of information you'd need to encode the same logic that could be transpiled to Java as well as Haskell. Have you thought at all about AST decorations that would indicate, for example, that something would need access to IO to execute?
Is it merely the usual reason (time/money), or have you, to some extent, lost confidence in the ideas?
I think many of the 625 people who starred this project, including myself, would be grateful to hear what your current thinking on it is.
I see that your using Nim now. I was recently reading the Nim docs and was very impressed. I told my boss: "it seems to have all the good parts of Scala, without the annoying dependence on Java". (note: I'm aware of Scala Native, and the main codebase I work on currently complies with its requirements, but in doing so forgoes the use of many popular Scala libraries, which tend to use new language features as soon as they're available).
Perhaps you are satisfied enough with Nim and Python as your go-to languages to abandon the more-ambitious/idealistic goals of Pseudo? I can imagine myself going down that path (abandoning my ideas that are similar to yours for Pseudo).
Hey! This is a really cool project. I've been considering something similar but ended up using regexes in order to translate a subset of javascript to c, java and c#: https://github.com/facebook/css-layout
Not really sure how you plan to use this but if you need a use case, I think that css-layout is a good one. It is non trivial but not that hard, already exists and is being used in production.
test.py:
a = True
b = False
Generate test.rb
by executing $ pseudo-python test.py test.rb
Generated test.rb
:
a = True
b = False
Expected test.rb
:
a = true
b = false
Document what can Pseudo do and translate several example programs, combine with pseudo-python
... this would allow for some of porting from Go to Python, etc,...
Input
class Barney:
def __init__(self):
self.status = 'not ok'
barney = Barney()
barney.status = "ok"
print(barney.status)
Output
class Barney
def initialize
@status = 'not ok'
end
end
barney = Barney.new
barney.status = 'ok'
puts barney.status
Error
undefined method
status=' for #<Barney:0x007f837084d190 @status="not ok"> (NoMethodError)`
In Python the not
operator has low precedence. In JS the !
operator has high precedence.
To be on the safe side, generators should wrap all operators in parens by default, and only remove them if the generator can prove there is no precedence/associativity issue. Otherwise you'll get issues with things like PHP's weird-ass left associative ternary operator.
Input (Python):
not 0.1 > 0.1
Expected output (JavaScript):
!(0.1 > 0.1)
Actual output (JavaScript):
!0.1 > 0.1
Tuples don't feel very C#
in some cases.
Use a middleware to detect suitable names for the tuples and their fields in the AST and if detected, generate a class with readonly fields for them and convert the index
accesses to attr
accesses
(based on angelvenchev and bella92 feedback)
Trying to translate this Python program to JS:
string = "test"
if "test" in string:
print("positive")
What I get is:
Pseudo error:
JSTranslator doesn't have a String#include? method
docs/library_reference.md
Trying to translate this Python program to JS:
string = "I am fine"
string = string.split(" ")
string = string[0]
What I get is:
can't change the type of variable string in global scope from String to List[String]
[x] Bug (Typo)
translateable
, however expect to see translatable
.targetting
, however expect to see targeting
.magnificient
, however expect to see magnificent
.compatibillity
, however expect to see compatibility
.Semi-automated issue generated by
https://github.com/timgates42/meticulous/blob/master/docs/NOTE.md
To avoid wasting CI processing resources a branch with the fix has been
prepared but a pull request has not yet been created. A pull request fixing
the issue can be prepared from the link below, feel free to create it or
request @timgates42 create the PR.
https://github.com/timgates42/pseudo/pull/new/bugfix_typos
Thanks.
test.py:
a = [x + 1 for x in [1, 2, 3]]
test.pseudo.yaml:
constants: []
custom_exceptions: []
definitions: []
dependencies: []
main:
- pseudo_type: Void
target:
name: a
pseudo_type: [List, Int]
type: local
type: assignment
value:
block:
- left: {name: x, pseudo_type: Int, type: local}
op: +
pseudo_type: Int
right: {pseudo_type: Int, type: int, value: 1}
type: binary_op
function: map
iterators:
iterator: {name: x, pseudo_type: Int, type: local}
type: for_iterator
pseudo_type: [List, Int]
sequences:
sequence:
elements:
- {pseudo_type: Int, type: int, value: 1}
- {pseudo_type: Int, type: int, value: 2}
- {pseudo_type: Int, type: int, value: 3}
pseudo_type: [List, Int]
type: list
type: for_sequence
type: standard_iterable_call
type: module
When executing $ pseudo test.pseudo.yaml py
, the following error occurs:
Traceback (most recent call last):
File "/usr/local/bin/pseudo", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.5/site-packages/pseudo/main.py", line 43, in main
output_source = pseudo.generate(pseudo.loader.as_tree(intermediate_code), format)
File "/usr/local/lib/python3.5/site-packages/pseudo/__init__.py", line 106, in generate
return GENERATORS[language]().generate(translated_ast)
File "/usr/local/lib/python3.5/site-packages/pseudo/code_generator.py", line 44, in generate
original = self._generate_node(tree)
File "/usr/local/lib/python3.5/site-packages/pseudo/code_generator.py", line 156, in _generate_node
return self._generate_from_template(self._parsed_templates[node.type], node, depth)
File "/usr/local/lib/python3.5/site-packages/pseudo/code_generator.py", line 210, in _generate_from_template
expanded.append(element.expand(self, node, depth))
File "/usr/local/lib/python3.5/site-packages/pseudo/code_generator_dsl.py", line 69, in expand
expanded = [generator._generate_node(content[0], depth)]
File "/usr/local/lib/python3.5/site-packages/pseudo/code_generator.py", line 156, in _generate_node
return self._generate_from_template(self._parsed_templates[node.type], node, depth)
File "/usr/local/lib/python3.5/site-packages/pseudo/code_generator.py", line 210, in _generate_from_template
expanded.append(element.expand(self, node, depth))
File "/usr/local/lib/python3.5/site-packages/pseudo/code_generator_dsl.py", line 29, in expand
return generator._generate_node(content, depth)
File "/usr/local/lib/python3.5/site-packages/pseudo/code_generator.py", line 156, in _generate_node
return self._generate_from_template(self._parsed_templates[node.type], node, depth)
File "/usr/local/lib/python3.5/site-packages/pseudo/code_generator.py", line 210, in _generate_from_template
expanded.append(element.expand(self, node, depth))
File "/usr/local/lib/python3.5/site-packages/pseudo/code_generator_dsl.py", line 63, in expand
content = getattr(node, self.field)
AttributeError: 'Node' object has no attribute 'test'
When
<call>(a, b, .. z[0], z[1]..z[<zlength - 1>])
and z is a Tuple / Array
, generate
<call>(a, b, *z>)
Eventually, for z[k]..z[l]
generate <call>(a, b, *z[k..l])
To replicate:
>cat add_two_arrays.py
def add_two_arrays(arrayA, arrayB):
return arrayA + arrayB
print(add_two_arrays([1,2,3], [4,5,6]))
>pseudo-python add_two_arrays.py
OK
saved pseudo ast as add_two_arrays.pseudo.yaml
>pseudo add_two_arrays.pseudo.yaml go
Traceback (most recent call last):
File "/usr/local/bin/pseudo", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.6/site-packages/pseudo/main.py", line 44, in main
output_source = pseudo.generate_from_yaml(intermediate_code, format)
File "/usr/local/lib/python3.6/site-packages/pseudo/__init__.py", line 97, in generate_from_yaml
return pseudo.generate(pseudo.loader.as_tree(pseudo_ast), language)
File "/usr/local/lib/python3.6/site-packages/pseudo/__init__.py", line 116, in generate
translated_ast = API_TRANSLATORS[language](pseudo_ast).api_translate()
File "/usr/local/lib/python3.6/site-packages/pseudo/api_translator.py", line 81, in api_translate
transformed = self.transform(self.tree)
File "/usr/local/lib/python3.6/site-packages/pseudo/tree_transformer.py", line 34, in transform
tree = self.transform_default(tree)
File "/usr/local/lib/python3.6/site-packages/pseudo/tree_transformer.py", line 54, in transform_default
setattr(tree, field, self.transform(child))
File "/usr/local/lib/python3.6/site-packages/pseudo/tree_transformer.py", line 41, in transform
return [self.transform(child) for child in tree]
File "/usr/local/lib/python3.6/site-packages/pseudo/tree_transformer.py", line 41, in <listcomp>
return [self.transform(child) for child in tree]
File "/usr/local/lib/python3.6/site-packages/pseudo/tree_transformer.py", line 34, in transform
tree = self.transform_default(tree)
File "/usr/local/lib/python3.6/site-packages/pseudo/tree_transformer.py", line 52, in transform_default
setattr(tree, field, self.transform_block(child))
File "/usr/local/lib/python3.6/site-packages/pseudo/tree_transformer.py", line 60, in transform_block
result = self.transform(child, True)
File "/usr/local/lib/python3.6/site-packages/pseudo/tree_transformer.py", line 34, in transform
tree = self.transform_default(tree)
File "/usr/local/lib/python3.6/site-packages/pseudo/tree_transformer.py", line 50, in transform_default
setattr(tree, field, self.transform(child, False, tree if tree.type[-10:] == 'assignment' else None))
File "/usr/local/lib/python3.6/site-packages/pseudo/tree_transformer.py", line 32, in transform
tree = handler(tree, in_block, assignment)
File "/usr/local/lib/python3.6/site-packages/pseudo/api_translator.py", line 148, in transform_standard_method_call
'%s doesn\'t have a %s#%s method' % (type(self).__name__, l, node.message))
pseudo.errors.PseudoStandardLibraryError: GolangTranslator doesn't have a List#concat method
You get this same error for C++, Ruby, JS and Python. Only C# is able to handle List#concat properly, and I am able to generate human-readable C# code using pseudo
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.