nicklockwood / Expression

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

Expression.parse("'\\n'") fails #32

Closed nighthawk closed 3 years ago

nighthawk commented 3 years ago

I've hit a funny little bug with this excellent library. I'm trying to evaluate an expression such as AnyExpression.parse(var1 + "'\\n'" + var2, ...), but this fails with an unexpectedToken("\\n\'"). If I modify it slightly to `AnyExpression.parse(var1 + "' \\n'" + var2, ...) it works -- notice the additional space.

The simplest way to reproduce this is Expression.parse("'\\n'").

It seems to be an issue with parseEscapedIdentifier and in particular this line:

while let part = scanCharacters({ $0 != delimiter && $0 != "\\" }) {

Unfortunately this implementation is going a bit over my head, so I haven't yet figured out how to fix this. Any advice would be much appreciated.

nighthawk commented 3 years ago

Solved it in the referenced PR.

nicklockwood commented 3 years ago

@nighthawk I've included your fix in 0.13.3