Permalink
Browse files

Implement generators and dict comprehensions

  • Loading branch information...
TotalVerb committed Jun 4, 2016
1 parent ce39c79 commit 4b52ae37998d7c534ba05cacf63251a2f5c07ece
Showing with 38 additions and 12 deletions.
  1. +7 −4 src/PythonSyntax.jl
  2. +0 −7 test/arrays.jl
  3. +21 −0 test/collections.jl
  4. +8 −0 test/iteration.jl
  5. +2 −1 test/runtests.jl
@@ -72,10 +72,13 @@ function transpile(t::PyObject)
ast.Set => :(Set($(transpile(:vect, t[:elts]))))
ast.ListComp => transpilecomp(t)
ast.SetComp => :(Set($(transpilecomp(t))))
ast.DictComp =>
error("Dictionary comprehensions are not yet supported.")
ast.GeneratorExp =>
error("Generators are not yet supported.")
ast.DictComp => Expr(:call, :Dict,
Expr(:generator,
Expr(:(=>), transpile(t[:key]), transpile(t[:value])),
transpilegen.(t[:generators])...))
ast.GeneratorExp => Expr(:generator,
transpile(t[:elt]),
transpilegen.(t[:generators])...)
ast.Await || ast.Yield || ast.YieldFrom =>
error("Generators are not yet supported.")
ast.Compare => transpilecmp(t)

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,21 @@
@testset "Arrays" begin
@test pysyntax"[1, 2, 3]" == [1, 2, 3]
@test pysyntax"[i for i in range(1, 10)]" == collect(1:10)
end # testset Arrays
@testset "Sets" begin
@test pysyntax"{1, 1, 1, 2}" == Set([1, 2])
@test pysyntax"{i**2 for i in range(-5, 11)}" == Set([0, 1, 4, 9, 16, 25])
end # testset Sets
@testset "Dicts" begin
@test pysyntax"{1: 2, 2: 3}" == Dict(1 => 2, 2 => 3)
@test pysyntax"{'hello': 'world'}" == Dict("hello" => "world")
@test pysyntax"{i: i**2 for i in range(1, 10)}" == Dict(i => i^2 for i in 1:10)
end # testset Dicts
@@ -0,0 +1,8 @@
@testset "Iteration" begin
@test pysyntax"sum(i**2 for i in range(1, 10))" == 385
@test pysyntax"""
collect(i + j for i in range(1, 2) for j in range(1, 2))
""" == [2 3; 3 4]
end # testset Iteration
@@ -7,5 +7,6 @@ include("io.jl")
include("functions.jl")
include("classes.jl")
include("magic.jl")
include("arrays.jl")
include("collections.jl")
include("iteration.jl")
include("stl.jl")

0 comments on commit 4b52ae3

Please sign in to comment.