nicklockwood / Expression

A cross-platform Swift library for evaluating mathematical expressions at runtime
MIT License
829 stars 51 forks source link

Square brackets #30

Closed MichalNekvasil closed 3 years ago

MichalNekvasil commented 3 years ago

Hello, I have problem with evaluating expression with square brackets.

In math it's OK to write [(10,3+10,1)*7]+3, but flee will not evaluate such expression..

Is there a way to make it work?

Thank you

P.S. of course I can replace square with round brackets, but it is not comfortable

nicklockwood commented 3 years ago

I suggest just preprocessing the expression string by replacing [ with ( and ] with ), e.g.

let expression = Expression(input.replacingOccurrences(of: "[", with: "(").replacingOccurrences(of: "]", with: ")"))