Not too complicated: you can either extract from the Expr, or parse the
tokens iterating over

(token, position) = parse(string, position, greedy = false)

and validate. The only tricky part is the signs.

On Sat, Oct 29 2016, Jérémy Béjanin wrote:

> How easy would it be to make one assuming the standard julia notation 3+4im?
>
> On Friday, October 28, 2016 at 3:58:08 PM UTC-4, Yichao Yu wrote:
>>
>> On Fri, Oct 28, 2016 at 3:53 PM, Jérémy Béjanin
>> <[email protected] <javascript:>> wrote:
>> > I've noticed that parsing a string representing a real number yields a
>> real
>> > number, but parsing a string representing a complex number yields an
>> > expression that must subsequently be evaluated. Is there a reason for
>> that
>> > behaviour? I'd like to avoid that behaviour considering I am reading
>> > user-inputted data.
>> >
>> > ```julia
>> > julia> typeof(parse("1.60254+3im"))
>> > Expr
>> >
>> > julia> typeof(parse("1.60254"))
>> > Float64
>> > ```
>>
>> Do no use `parse(::String)` to parse numbers. It is for parsing
>> generic julia code. Use `parse(Float64, str)` to parse a floating
>> point number.
>>
>> I don't think we have a parsing function for complex number likely
>> because there isn't a universal standard.
>>

Reply via email to