diff --git a/CHANGELOG.md b/CHANGELOG.md index c96c1c3..c79682c 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## [0.8.4](/~https://github.com/nicklockwood/Expression/releases/tag/0.8.4) (2017-08-22) + +- Fixed spurious parsing errors when expressions have leading whitespace +- The `parse(_: String.UnicodeScalarView)` method now accepts an optional list of terminating delimiters + ## [0.8.3](/~https://github.com/nicklockwood/Expression/releases/tag/0.8.3) (2017-08-16) - Fixed crash when parsing a malformed expression that contains just a single operator diff --git a/Expression.podspec.json b/Expression.podspec.json index 1593aa8..23783b5 100644 --- a/Expression.podspec.json +++ b/Expression.podspec.json @@ -1,6 +1,6 @@ { "name": "Expression", - "version": "0.8.3", + "version": "0.8.4", "license": { "type": "zlib", "file": "LICENCE.md" @@ -10,7 +10,7 @@ "authors": "Nick Lockwood", "source": { "git": "/~https://github.com/nicklockwood/Expression.git", - "tag": "0.8.3" + "tag": "0.8.4" }, "source_files": "Sources", "requires_arc": true, diff --git a/README.md b/README.md index d7280f8..e3307be 100644 --- a/README.md +++ b/README.md @@ -267,6 +267,16 @@ let expression = Expression(parsedExpression, constants: ["foo": 4, "bar": 5]) By setting the `usingCache` argument to `false` in the code above, we avoid adding the expression to the global cache. You are also free to implement your own caching by storing the parsed expression and re-using it, which may be more efficient than the built-in cache in some cases (e.g. by avoiding thread management if your code is single-threaded). +A second variant of the `Expression.parse()` method accepts a `String.UnicodeScalarView.SubSequence` and optional list of terminating delimiter strings. This can be used to match an expression embedded inside a longer string, and leaves the `startIndex` of the character sequence in the right place to continue parsing once the delimiter is reached: + +```swift +let expressionString = "lorem ipsum {foo + bar} dolor sit" +var characters = String.UnicodeScalarView.SubSequence(expression.unicodeScalars) +while characters.popFirst() != "{" {} // Read up to start of expression +let parsedExpression = Expression.parse(&characters, upTo: "}") +let expression = Expression(parsedExpression, constants: ["foo": 4, "bar": 5]) +``` + ## Optimization By default, expressions are optimized where possible to make evaluation more efficient. Common optimizations include replacing constants with their literal values, and replacing pure functions or operators with their result when all arguments are constant. diff --git a/Sources/Expression.swift b/Sources/Expression.swift index 50cf16b..fc485c1 100644 --- a/Sources/Expression.swift +++ b/Sources/Expression.swift @@ -2,7 +2,7 @@ // Expression.swift // Expression // -// Version 0.8.3 +// Version 0.8.4 // // Created by Nick Lockwood on 15/09/2016. // Copyright © 2016 Nick Lockwood. All rights reserved. diff --git a/Sources/Info.plist b/Sources/Info.plist index 100cfa3..ec3bd7e 100644 --- a/Sources/Info.plist +++ b/Sources/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.8.3 + 0.8.4 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSHumanReadableCopyright