Ok that one is not in the manual... Base.parse_input_line() is what you
want.
julia> ex = """
a = 1
b = 2
a + b
"""
"a = 1\nb = 2\na + b\n"
julia> ast = Base.parse_input_line(ex)
:($(Expr(:toplevel, :(a = 1), :(b = 2), :(+(a,b)))))
julia> ast.head
:toplevel
julia> ast.args
3-element Array{Any,1}:
:(a = 1)
:(b = 2)
:(+(a,b))
On Thursday, February 6, 2014 9:09:40 PM UTC-5, Pierre-Yves Gérardy wrote:
>
> You can use quote:
>
> julia> ex = quote
> a = 1
> b = 2
> a + b
> end
> quote # none, line 2:
> a = 1 # line 3:
> b = 2 # line 4:
> +(a,b)
> end
>
> julia> typeof(ex)
> Expr
>
> julia> eval(ex)
> 3
>
> On Friday, February 7, 2014 2:45:34 AM UTC+1, Fil Mackay wrote:
>>
>> On Friday, February 7, 2014 11:59:21 AM UTC+11, Jake Bolewski wrote:
>>>
>>> Hey Ethan, what you are looking for is include_string:
>>>
>>
>> Thanks - even covered in the introduction (missed that..)
>>
>> julia> include_string("""
>>> a = 1
>>> b = 2
>>> a + b
>>> """)
>>> 3
>>>
>>
>> Is there a way to get an Expr-ish representation of the above - ie. parse
>> but not execute it (yet). It could return it as a root Expr that contains
>> two sub-Exprs?
>>
>>