From f0c26ca0fcf9285b463421c28875c9edf91c3a69 Mon Sep 17 00:00:00 2001 From: thautwarm Date: Sat, 10 Aug 2019 00:59:38 +0800 Subject: [PATCH] #7 again, another issue --- src/ASTGen.jl | 6 ++++++ test/test_case1.jl | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/ASTGen.jl b/src/ASTGen.jl index 2b3e42b..5fd38f4 100644 --- a/src/ASTGen.jl +++ b/src/ASTGen.jl @@ -418,6 +418,12 @@ function to_ast(filename, python :: Dict) call(op, apply(left), apply(right)) end + # for Python 3.8+ + (Record(:class => "Constant", value) + || # for Python 3.7- and 3.7 + Record(:class => "NameConstant", value) + ) -> value + Record(:class=> "Compare", left, ops, comparators) -> foldl(zip(ops, comparators) |> collect, init=apply(left)) do last, (op, comparator) let comparator = apply(comparator) diff --git a/test/test_case1.jl b/test/test_case1.jl index fc3f630..478d780 100644 --- a/test/test_case1.jl +++ b/test/test_case1.jl @@ -27,6 +27,7 @@ result = sum_by(lambda x: x * 10, [1, 2, 3]) @test result == 60 @test sum_by(identity, [1, 2, 3]) === 6 end + py2jl""" def __BOND_repl(): SENTINEL = 1 @@ -37,4 +38,15 @@ def __BOND_repl(): @testset "while & compare" begin @test __BOND_repl() == 1 end + + py2jl""" + def __BOND_repl(): + SENTINEL = 10 + while True: + break + return SENTINEL + """ + @testset "True" begin + @test __BOND_repl() == 10 + end end \ No newline at end of file